diff --git a/example/ExaNIC_X10/fpga/Makefile b/example/ExaNIC_X10/fpga/Makefile new file mode 100644 index 0000000..f504bd0 --- /dev/null +++ b/example/ExaNIC_X10/fpga/Makefile @@ -0,0 +1,25 @@ +# Targets +TARGETS:= + +# Subdirectories +SUBDIRS = fpga +SUBDIRS_CLEAN = $(patsubst %,%.clean,$(SUBDIRS)) + +# Rules +.PHONY: all +all: $(SUBDIRS) $(TARGETS) + +.PHONY: $(SUBDIRS) +$(SUBDIRS): + cd $@ && $(MAKE) + +.PHONY: $(SUBDIRS_CLEAN) +$(SUBDIRS_CLEAN): + cd $(@:.clean=) && $(MAKE) clean + +.PHONY: clean +clean: $(SUBDIRS_CLEAN) + -rm -rf $(TARGETS) + +program: + #djtgcfg prog -d Atlys --index 0 --file fpga/fpga.bit diff --git a/example/ExaNIC_X10/fpga/README.md b/example/ExaNIC_X10/fpga/README.md new file mode 100644 index 0000000..7380aea --- /dev/null +++ b/example/ExaNIC_X10/fpga/README.md @@ -0,0 +1,26 @@ +# Verilog Ethernet ExaNIC X10 Example Design + +## Introduction + +This example design targets the Exablaze ExaNIC X10 FPGA board. + +The design implements the PCIe AXI lite master module, the PCIe AXI master +module, and the PCIe AXI DMA module. A very simple Linux driver is included +to test the FPGA design. + +FPGA: xcku035-fbva676-2-c + +## How to build + +Run make to build. Ensure that the Xilinx Vivado toolchain components are +in PATH. + +Run make to build the driver. Ensure the headers for the running kernel are +installed, otherwise the driver cannot be compiled. + +## How to test + +Run make program to program the ExaNIC X10 board with Vivado. Then load the +driver with insmod example.ko. Check dmesg for the output. + + diff --git a/example/ExaNIC_X10/fpga/common/vivado.mk b/example/ExaNIC_X10/fpga/common/vivado.mk new file mode 100644 index 0000000..964ed04 --- /dev/null +++ b/example/ExaNIC_X10/fpga/common/vivado.mk @@ -0,0 +1,118 @@ +################################################################### +# +# Xilinx Vivado FPGA Makefile +# +# Copyright (c) 2016 Alex Forencich +# +################################################################### +# +# Parameters: +# FPGA_TOP - Top module name +# FPGA_FAMILY - FPGA family (e.g. VirtexUltrascale) +# FPGA_DEVICE - FPGA device (e.g. xcvu095-ffva2104-2-e) +# SYN_FILES - space-separated list of source files +# INC_FILES - space-separated list of include files +# XDC_FILES - space-separated list of timing constraint files +# XCI_FILES - space-separated list of IP XCI files +# +# Example: +# +# FPGA_TOP = fpga +# FPGA_FAMILY = VirtexUltrascale +# FPGA_DEVICE = xcvu095-ffva2104-2-e +# SYN_FILES = rtl/fpga.v +# XDC_FILES = fpga.xdc +# XCI_FILES = ip/pcspma.xci +# include ../common/vivado.mk +# +################################################################### + +# phony targets +.PHONY: clean fpga + +# prevent make from deleting intermediate files and reports +.PRECIOUS: %.xpr %.bit %.mcs %.prm +.SECONDARY: + +CONFIG ?= config.mk +-include ../$(CONFIG) + +SYN_FILES_REL = $(patsubst %, ../%, $(SYN_FILES)) +INC_FILES_REL = $(patsubst %, ../%, $(INC_FILES)) +XCI_FILES_REL = $(patsubst %, ../%, $(XCI_FILES)) + +ifdef XDC_FILES + XDC_FILES_REL = $(patsubst %, ../%, $(XDC_FILES)) +else + XDC_FILES_REL = $(FPGA_TOP).xdc +endif + +################################################################### +# Main Targets +# +# all: build everything +# clean: remove output files and project files +################################################################### + +all: fpga + +fpga: $(FPGA_TOP).bit + +tmpclean: + -rm -rf *.log *.jou *.cache *.hw *.ip_user_files *.runs *.xpr *.html *.xml *.sim *.srcs *.str .Xil defines.v + -rm -rf create_project.tcl run_synth.tcl run_impl.tcl generate_bit.tcl + +clean: tmpclean + -rm -rf *.bit program.tcl generate_mcs.tcl *.mcs *.prm flash.tcl + +distclean: clean + -rm -rf rev + +################################################################### +# Target implementations +################################################################### + +# Vivado project file +%.xpr: Makefile $(XCI_FILES_REL) + rm -rf defines.v + touch defines.v + for x in $(DEFS); do echo '`define' $$x >> defines.v; done + echo "create_project -force -part $(FPGA_PART) $*" > create_project.tcl + echo "add_files -fileset sources_1 defines.v" >> create_project.tcl + for x in $(SYN_FILES_REL); do echo "add_files -fileset sources_1 $$x" >> create_project.tcl; done + for x in $(XDC_FILES_REL); do echo "add_files -fileset constrs_1 $$x" >> create_project.tcl; done + for x in $(XCI_FILES_REL); do echo "import_ip $$x" >> create_project.tcl; done + echo "exit" >> create_project.tcl + vivado -nojournal -nolog -mode batch -source create_project.tcl + +# synthesis run +%.runs/synth_1/%.dcp: %.xpr $(SYN_FILES_REL) $(INC_FILES_REL) $(XDC_FILES_REL) + echo "open_project $*.xpr" > run_synth.tcl + echo "reset_run synth_1" >> run_synth.tcl + echo "launch_runs synth_1" >> run_synth.tcl + echo "wait_on_run synth_1" >> run_synth.tcl + echo "exit" >> run_synth.tcl + vivado -nojournal -nolog -mode batch -source run_synth.tcl + +# implementation run +%.runs/impl_1/%_routed.dcp: %.runs/synth_1/%.dcp + echo "open_project $*.xpr" > run_impl.tcl + echo "reset_run impl_1" >> run_impl.tcl + echo "launch_runs impl_1" >> run_impl.tcl + echo "wait_on_run impl_1" >> run_impl.tcl + echo "exit" >> run_impl.tcl + vivado -nojournal -nolog -mode batch -source run_impl.tcl + +# bit file +%.bit: %.runs/impl_1/%_routed.dcp + echo "open_project $*.xpr" > generate_bit.tcl + echo "open_run impl_1" >> generate_bit.tcl + echo "write_bitstream -force $*.bit" >> generate_bit.tcl + echo "exit" >> generate_bit.tcl + vivado -nojournal -nolog -mode batch -source generate_bit.tcl + mkdir -p rev + EXT=bit; COUNT=100; \ + while [ -e rev/$*_rev$$COUNT.$$EXT ]; \ + do COUNT=$$((COUNT+1)); done; \ + cp $@ rev/$*_rev$$COUNT.$$EXT; \ + echo "Output: rev/$*_rev$$COUNT.$$EXT"; diff --git a/example/ExaNIC_X10/fpga/driver/Makefile b/example/ExaNIC_X10/fpga/driver/Makefile new file mode 100644 index 0000000..46f7ba2 --- /dev/null +++ b/example/ExaNIC_X10/fpga/driver/Makefile @@ -0,0 +1,11 @@ + +# object files to build +obj-m += example.o +example-objs += example_driver.o + +all: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + +clean: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean + diff --git a/example/ExaNIC_X10/fpga/driver/example_driver.c b/example/ExaNIC_X10/fpga/driver/example_driver.c new file mode 100644 index 0000000..e909ca8 --- /dev/null +++ b/example/ExaNIC_X10/fpga/driver/example_driver.c @@ -0,0 +1,371 @@ +/* + +Copyright (c) 2018 Alex Forencich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +#include "example_driver.h" +#include +#include +#include +#include + +MODULE_DESCRIPTION("verilog-pcie exmaple driver"); +MODULE_AUTHOR("Alex Forencich"); +MODULE_LICENSE("Dual MIT/GPL"); +MODULE_VERSION(DRIVER_VERSION); +MODULE_SUPPORTED_DEVICE(DRIVER_NAME); + +static int edev_probe(struct pci_dev *pdev, const struct pci_device_id *ent); +static void edev_remove(struct pci_dev *pdev); +static void edev_shutdown(struct pci_dev *pdev); + +static int enumerate_bars(struct example_dev *edev, struct pci_dev *pdev); +static int map_bars(struct example_dev *edev, struct pci_dev *pdev); +static void free_bars(struct example_dev *edev, struct pci_dev *pdev); + +static const struct pci_device_id pci_ids[] = { + { PCI_DEVICE(0x1234, 0x0001) }, + { 0 /* end */ } +}; + +MODULE_DEVICE_TABLE(pci, pci_ids); + +static irqreturn_t edev_intr(int irq, void *data) +{ + struct example_dev *edev = data; + struct device *dev = &edev->pdev->dev; + + edev->irqcount++; + + dev_info(dev, "Interrupt"); + + return IRQ_HANDLED; +} + +static int edev_probe(struct pci_dev *pdev, const struct pci_device_id *ent) +{ + int ret = 0; + struct example_dev *edev; + struct device *dev = &pdev->dev; + + int k; + + dev_info(dev, "edev probe"); + dev_info(dev, " vendor: 0x%04x", pdev->vendor); + dev_info(dev, " device: 0x%04x", pdev->device); + dev_info(dev, " class: 0x%06x", pdev->class); + dev_info(dev, " pci id: %02x:%02x.%02x", pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); + + if (!(edev = devm_kzalloc(dev, sizeof(struct example_dev), GFP_KERNEL))) { + return -ENOMEM; + } + + edev->pdev = pdev; + pci_set_drvdata(pdev, edev); + + // Allocate DMA buffer + edev->dma_region_len = 16*1024; + edev->dma_region = dma_alloc_coherent(dev, edev->dma_region_len, &edev->dma_region_addr, GFP_KERNEL | __GFP_ZERO); + if (!edev->dma_region) + { + dev_err(dev, "Failed to allocate DMA buffer"); + ret = -ENOMEM; + goto fail_dma_alloc; + } + + dev_info(dev, "Allocated DMA region virt %p, phys %p", edev->dma_region, (void *)edev->dma_region_addr); + + // Disable ASPM + pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); + + // Enable device + ret = pci_enable_device_mem(pdev); + if (ret) + { + dev_err(dev, "Failed to enable PCI device"); + //ret = -ENODEV; + goto fail_enable_device; + } + + // Enable bus mastering for DMA + pci_set_master(pdev); + + // Reserve regions + ret = pci_request_regions(pdev, DRIVER_NAME); + if (ret) + { + dev_err(dev, "Failed to reserve regions"); + //ret = -EBUSY; + goto fail_regions; + } + + // Enumerate BARs + enumerate_bars(edev, pdev); + + // Map BARs + ret = map_bars(edev, pdev); + if (ret) + { + dev_err(dev, "Failed to map BARs"); + goto fail_map_bars; + } + + // Allocate MSI IRQs + ret = pci_alloc_irq_vectors(pdev, 1, 32, PCI_IRQ_MSI); + if (ret < 0) + { + dev_err(dev, "Failed to allocate IRQs"); + goto fail_map_bars; + } + + // Set up interrupt + ret = pci_request_irq(pdev, 0, edev_intr, 0, edev, "edev"); + if (ret < 0) + { + dev_err(dev, "Failed to request IRQ"); + goto fail_irq; + } + + // Dump counters + dev_info(dev, "TLP counters"); + dev_info(dev, "RQ: %d", ioread32(edev->bar[0]+0x000400)); + dev_info(dev, "RC: %d", ioread32(edev->bar[0]+0x000404)); + dev_info(dev, "CQ: %d", ioread32(edev->bar[0]+0x000408)); + dev_info(dev, "CC: %d", ioread32(edev->bar[0]+0x00040C)); + + // Read/write test + dev_info(dev, "write to BAR1"); + iowrite32(0x11223344, edev->bar[1]); + + dev_info(dev, "read from BAR1"); + dev_info(dev, "%08x", ioread32(edev->bar[1])); + + // Dump counters + dev_info(dev, "TLP counters"); + dev_info(dev, "RQ: %d", ioread32(edev->bar[0]+0x000400)); + dev_info(dev, "RC: %d", ioread32(edev->bar[0]+0x000404)); + dev_info(dev, "CQ: %d", ioread32(edev->bar[0]+0x000408)); + dev_info(dev, "CC: %d", ioread32(edev->bar[0]+0x00040C)); + + // PCIe DMA test + dev_info(dev, "write test data"); + for (k = 0; k < 256; k++) + { + ((char *)edev->dma_region)[k] = k; + } + + dev_info(dev, "read test data"); + print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1, edev->dma_region, 256, true); + + dev_info(dev, "check DMA enable"); + dev_info(dev, "%08x", ioread32(edev->bar[0]+0x000000)); + + dev_info(dev, "enable DMA"); + iowrite32(0x1, edev->bar[0]+0x000000); + + dev_info(dev, "check DMA enable"); + dev_info(dev, "%08x", ioread32(edev->bar[0]+0x000000)); + + dev_info(dev, "start copy to card"); + iowrite32((edev->dma_region_addr+0x0000)&0xffffffff, edev->bar[0]+0x000100); + iowrite32(((edev->dma_region_addr+0x0000) >> 32)&0xffffffff, edev->bar[0]+0x000104); + iowrite32(0x100, edev->bar[0]+0x000108); + iowrite32(0, edev->bar[0]+0x00010C); + iowrite32(0x100, edev->bar[0]+0x000110); + iowrite32(0xAA, edev->bar[0]+0x000114); + + msleep(1); + + dev_info(dev, "Read status"); + dev_info(dev, "%08x", ioread32(edev->bar[0]+0x000118)); + + dev_info(dev, "start copy to host"); + iowrite32((edev->dma_region_addr+0x0200)&0xffffffff, edev->bar[0]+0x000200); + iowrite32(((edev->dma_region_addr+0x0200) >> 32)&0xffffffff, edev->bar[0]+0x000204); + iowrite32(0x100, edev->bar[0]+0x000208); + iowrite32(0, edev->bar[0]+0x00020C); + iowrite32(0x100, edev->bar[0]+0x000210); + iowrite32(0x55, edev->bar[0]+0x000214); + + msleep(1); + + dev_info(dev, "Read status"); + dev_info(dev, "%08x", ioread32(edev->bar[0]+0x000218)); + + dev_info(dev, "read test data"); + print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1, edev->dma_region+0x0200, 256, true); + + // Dump counters + dev_info(dev, "TLP counters"); + dev_info(dev, "RQ: %d", ioread32(edev->bar[0]+0x000400)); + dev_info(dev, "RC: %d", ioread32(edev->bar[0]+0x000404)); + dev_info(dev, "CQ: %d", ioread32(edev->bar[0]+0x000408)); + dev_info(dev, "CC: %d", ioread32(edev->bar[0]+0x00040C)); + + // probe complete + return 0; + + // error handling +fail_irq: + pci_free_irq_vectors(pdev); +fail_map_bars: + free_bars(edev, pdev); + pci_release_regions(pdev); +fail_regions: + pci_clear_master(pdev); + pci_disable_device(pdev); +fail_enable_device: + dma_free_coherent(dev, edev->dma_region_len, edev->dma_region, edev->dma_region_addr); +fail_dma_alloc: + return ret; +} + +static void edev_remove(struct pci_dev *pdev) +{ + struct example_dev *edev; + struct device *dev = &pdev->dev; + + dev_info(dev, "edev remove"); + + if (!(edev = pci_get_drvdata(pdev))) { + return; + } + + pci_free_irq(pdev, 0, edev); + pci_free_irq_vectors(pdev); + free_bars(edev, pdev); + pci_release_regions(pdev); + pci_clear_master(pdev); + pci_disable_device(pdev); + dma_free_coherent(dev, edev->dma_region_len, edev->dma_region, edev->dma_region_addr); +} + +static void edev_shutdown(struct pci_dev *pdev) +{ + struct example_dev *edev = pci_get_drvdata(pdev); + struct device *dev = &pdev->dev; + + dev_info(dev, "edev shutdown"); + + if (!edev) { + return; + } + + // ensure DMA is disabled on shutdown + pci_clear_master(pdev); +} + +static int enumerate_bars(struct example_dev *edev, struct pci_dev *pdev) +{ + struct device *dev = &pdev->dev; + int i; + + for (i = 0; i < DEV_BAR_CNT; i++) + { + resource_size_t bar_start = pci_resource_start(pdev, i); + if (bar_start) + { + resource_size_t bar_end = pci_resource_end(pdev, i); + unsigned long bar_flags = pci_resource_flags(pdev, i); + dev_info(dev, "BAR[%d] 0x%08llx-0x%08llx flags 0x%08lx", + i, bar_start, bar_end, bar_flags); + } + } + + return 0; +} + +static int map_bars(struct example_dev *edev, struct pci_dev *pdev) +{ + struct device *dev = &pdev->dev; + int i; + + for (i = 0; i < DEV_BAR_CNT; i++) + { + resource_size_t bar_start = pci_resource_start(pdev, i); + resource_size_t bar_end = pci_resource_end(pdev, i); + resource_size_t bar_len = bar_end - bar_start + 1; + edev->bar_len[i] = bar_len; + + if (!bar_start || !bar_end) + { + edev->bar_len[i] = 0; + continue; + } + + if (bar_len < 1) + { + dev_warn(dev, "BAR[%d] is less than 1 byte", i); + continue; + } + + edev->bar[i] = pci_ioremap_bar(pdev, i); + + if (!edev->bar[i]) + { + dev_err(dev, "Could not map BAR[%d]", i); + return -1; + } + + dev_info(dev, "BAR[%d] mapped at 0x%p with length %llu", i, edev->bar[i], bar_len); + } + + return 0; +} + +static void free_bars(struct example_dev *edev, struct pci_dev *pdev) +{ + struct device *dev = &pdev->dev; + int i; + + for (i = 0; i < DEV_BAR_CNT; i++) + { + if (edev->bar[i]) + { + pci_iounmap(pdev, edev->bar[i]); + edev->bar[i] = NULL; + dev_info(dev, "Unmapped BAR[%d]", i); + } + } +} + +static struct pci_driver pci_driver = { + .name = DRIVER_NAME, + .id_table = pci_ids, + .probe = edev_probe, + .remove = edev_remove, + .shutdown = edev_shutdown +}; + +static int __init edev_init(void) +{ + return pci_register_driver(&pci_driver); +} + +static void __exit edev_exit(void) +{ + pci_unregister_driver(&pci_driver); +} + +module_init(edev_init); +module_exit(edev_exit); + diff --git a/example/ExaNIC_X10/fpga/driver/example_driver.h b/example/ExaNIC_X10/fpga/driver/example_driver.h new file mode 100644 index 0000000..9054bbc --- /dev/null +++ b/example/ExaNIC_X10/fpga/driver/example_driver.h @@ -0,0 +1,50 @@ +/* + +Copyright (c) 2018 Alex Forencich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +#ifndef EXAMPLE_DRIVER_H +#define EXAMPLE_DRIVER_H + +#include + +#define DRIVER_NAME "edev" +#define DRIVER_VERSION "0.1" + +#define DEV_BAR_CNT 2 + +struct example_dev { + struct pci_dev *pdev; + + // BAR pointers + void * __iomem bar[DEV_BAR_CNT]; + resource_size_t bar_len[DEV_BAR_CNT]; + + // DMA buffer + size_t dma_region_len; + void *dma_region; + dma_addr_t dma_region_addr; + + int irqcount; +}; + +#endif /* EXAMPLE_DRIVER_H */ diff --git a/example/ExaNIC_X10/fpga/fpga.xdc b/example/ExaNIC_X10/fpga/fpga.xdc new file mode 100644 index 0000000..5a3d1c3 --- /dev/null +++ b/example/ExaNIC_X10/fpga/fpga.xdc @@ -0,0 +1,153 @@ +# XDC constraints for the ExaNIC X10 +# part: xcku035-fbva676-2-e + +# General configuration +set_property CFGBVS GND [current_design] +set_property CONFIG_VOLTAGE 1.8 [current_design] +set_property BITSTREAM.GENERAL.COMPRESS true [current_design] +set_property BITSTREAM.CONFIG.UNUSEDPIN Pullup [current_design] +set_property BITSTREAM.CONFIG.CONFIGRATE 50 [current_design] +set_property BITSTREAM.CONFIG.BPI_SYNC_MODE Type2 [current_design] +set_property CONFIG_MODE BPI16 [current_design] + +# 100 MHz system clock +#set_property -dict {LOC D18 IOSTANDARD LVDS} [get_ports clk_100mhz_p] +#set_property -dict {LOC C18 IOSTANDARD LVDS} [get_ports clk_100mhz_n] +#create_clock -period 10 -name clk_100mhz [get_ports clk_100mhz_p] + +# LEDs +set_property -dict {LOC A25 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12} [get_ports {sfp_1_led[0]}] +set_property -dict {LOC A24 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12} [get_ports {sfp_1_led[1]}] +set_property -dict {LOC E23 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12} [get_ports {sfp_2_led[0]}] +set_property -dict {LOC D26 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12} [get_ports {sfp_2_led[1]}] +set_property -dict {LOC C23 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12} [get_ports {sma_led[0]}] +set_property -dict {LOC D23 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12} [get_ports {sma_led[1]}] + +# GPIO +#set_property -dict {LOC W26 IOSTANDARD LVCMOS18} [get_ports gpio[0]] +#set_property -dict {LOC Y26 IOSTANDARD LVCMOS18} [get_ports gpio[1]] +#set_property -dict {LOC AB26 IOSTANDARD LVCMOS18} [get_ports gpio[2]] +#set_property -dict {LOC AC26 IOSTANDARD LVCMOS18} [get_ports gpio[3]] + +# SMA +#set_property -dict {LOC B17 IOSTANDARD LVCMOS18} [get_ports sma_in] +#set_property -dict {LOC B16 IOSTANDARD LVCMOS18} [get_ports sma_out] +#set_property -dict {LOC B19 IOSTANDARD LVCMOS18} [get_ports sma_out_en] +#set_property -dict {LOC C16 IOSTANDARD LVCMOS18} [get_ports sma_term_en] + +# SFP+ Interface +#set_property -dict {LOC D2 } [get_ports sfp_1_rx_p] ;# MGTHTXN0_227 GTHE3_CHANNEL_X0Y12 / GTHE3_COMMON_X0Y3 +#set_property -dict {LOC D1 } [get_ports sfp_1_rx_n] ;# MGTHTXP0_227 GTHE3_CHANNEL_X0Y12 / GTHE3_COMMON_X0Y3 +#set_property -dict {LOC E4 } [get_ports sfp_1_tx_p] ;# MGTHTXN0_227 GTHE3_CHANNEL_X0Y12 / GTHE3_COMMON_X0Y3 +#set_property -dict {LOC E3 } [get_ports sfp_1_tx_n] ;# MGTHTXP0_227 GTHE3_CHANNEL_X0Y12 / GTHE3_COMMON_X0Y3 +#set_property -dict {LOC C4 } [get_ports sfp_2_rx_p] ;# MGTHTXN1_227 GTHE3_CHANNEL_X0Y13 / GTHE3_COMMON_X0Y3 +#set_property -dict {LOC C3 } [get_ports sfp_2_rx_n] ;# MGTHTXP1_227 GTHE3_CHANNEL_X0Y13 / GTHE3_COMMON_X0Y3 +#set_property -dict {LOC D6 } [get_ports sfp_2_tx_p] ;# MGTHTXN1_227 GTHE3_CHANNEL_X0Y13 / GTHE3_COMMON_X0Y3 +#set_property -dict {LOC D5 } [get_ports sfp_2_tx_n] ;# MGTHTXP1_227 GTHE3_CHANNEL_X0Y13 / GTHE3_COMMON_X0Y3 +#set_property -dict {LOC H6 } [get_ports sfp_mgt_refclk_p] ;# MGTREFCLK0P_227 from X2 +#set_property -dict {LOC H5 } [get_ports sfp_mgt_refclk_n] ;# MGTREFCLK0N_227 from X2 +#set_property -dict {LOC AA12 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12} [get_ports sfp_1_tx_disable] +#set_property -dict {LOC W14 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12} [get_ports sfp_2_tx_disable] +#set_property -dict {LOC C24 IOSTANDARD LVCMOS18 PULLUP true} [get_ports sfp_1_npres] +#set_property -dict {LOC D24 IOSTANDARD LVCMOS18 PULLUP true} [get_ports sfp_2_npres] +#set_property -dict {LOC W13 IOSTANDARD LVCMOS18 PULLUP true} [get_ports sfp_1_los] +#set_property -dict {LOC AB12 IOSTANDARD LVCMOS18 PULLUP true} [get_ports sfp_2_los] +#set_property -dict {LOC B25 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12} [get_ports sfp_1_rs] +#set_property -dict {LOC D25 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12} [get_ports sfp_2_rs] +#set_property -dict {LOC W11 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12 PULLUP true} [get_ports sfp_i2c_scl] +#set_property -dict {LOC Y11 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12 PULLUP true} [get_ports sfp_1_i2c_sda] +#set_property -dict {LOC Y13 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12 PULLUP true} [get_ports sfp_2_i2c_sda] + +# 161.1328125 MHz MGT reference clock +#create_clock -period 6.206 -name sfp_mgt_refclk [get_ports sfp_mgt_refclk_p] + +# I2C interface +#set_property -dict {LOC B26 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12 PULLUP true} [get_ports eeprom_i2c_scl] +#set_property -dict {LOC C26 IOSTANDARD LVCMOS18 SLEW SLOW DRIVE 12 PULLUP true} [get_ports eeprom_i2c_sda] + +# PCIe Interface +set_property -dict {LOC AF2 } [get_ports {pcie_rx_p[7]}] ;# MGTHTXN0_224 GTHE3_CHANNEL_X0Y0 / GTHE3_COMMON_X0Y0 +#set_property -dict {LOC AF1 } [get_ports {pcie_rx_n[7]}] ;# MGTHTXP0_224 GTHE3_CHANNEL_X0Y0 / GTHE3_COMMON_X0Y0 +set_property -dict {LOC AF6 } [get_ports {pcie_tx_p[7]}] ;# MGTHTXN0_224 GTHE3_CHANNEL_X0Y0 / GTHE3_COMMON_X0Y0 +#set_property -dict {LOC AF5 } [get_ports {pcie_tx_n[7]}] ;# MGTHTXP0_224 GTHE3_CHANNEL_X0Y0 / GTHE3_COMMON_X0Y0 +set_property -dict {LOC AE4 } [get_ports {pcie_rx_p[6]}] ;# MGTHTXN1_224 GTHE3_CHANNEL_X0Y1 / GTHE3_COMMON_X0Y0 +#set_property -dict {LOC AE3 } [get_ports {pcie_rx_n[6]}] ;# MGTHTXP1_224 GTHE3_CHANNEL_X0Y1 / GTHE3_COMMON_X0Y0 +set_property -dict {LOC AD6 } [get_ports {pcie_tx_p[6]}] ;# MGTHTXN1_224 GTHE3_CHANNEL_X0Y1 / GTHE3_COMMON_X0Y0 +#set_property -dict {LOC AD5 } [get_ports {pcie_tx_n[6]}] ;# MGTHTXP1_224 GTHE3_CHANNEL_X0Y1 / GTHE3_COMMON_X0Y0 +set_property -dict {LOC AD2 } [get_ports {pcie_rx_p[5]}] ;# MGTHTXN2_224 GTHE3_CHANNEL_X0Y2 / GTHE3_COMMON_X0Y0 +#set_property -dict {LOC AD1 } [get_ports {pcie_rx_n[5]}] ;# MGTHTXP2_224 GTHE3_CHANNEL_X0Y2 / GTHE3_COMMON_X0Y0 +set_property -dict {LOC AC4 } [get_ports {pcie_tx_p[5]}] ;# MGTHTXN2_224 GTHE3_CHANNEL_X0Y2 / GTHE3_COMMON_X0Y0 +#set_property -dict {LOC AC3 } [get_ports {pcie_tx_n[5]}] ;# MGTHTXP2_224 GTHE3_CHANNEL_X0Y2 / GTHE3_COMMON_X0Y0 +set_property -dict {LOC AB2 } [get_ports {pcie_rx_p[4]}] ;# MGTHTXN3_224 GTHE3_CHANNEL_X0Y3 / GTHE3_COMMON_X0Y0 +#set_property -dict {LOC AB1 } [get_ports {pcie_rx_n[4]}] ;# MGTHTXP3_224 GTHE3_CHANNEL_X0Y3 / GTHE3_COMMON_X0Y0 +set_property -dict {LOC AB6 } [get_ports {pcie_tx_p[4]}] ;# MGTHTXN3_224 GTHE3_CHANNEL_X0Y3 / GTHE3_COMMON_X0Y0 +#set_property -dict {LOC AB5 } [get_ports {pcie_tx_n[4]}] ;# MGTHTXP3_224 GTHE3_CHANNEL_X0Y3 / GTHE3_COMMON_X0Y0 +set_property -dict {LOC Y2 } [get_ports {pcie_rx_p[3]}] ;# MGTHTXN0_225 GTHE3_CHANNEL_X0Y4 / GTHE3_COMMON_X0Y1 +#set_property -dict {LOC Y1 } [get_ports {pcie_rx_n[3]}] ;# MGTHTXP0_225 GTHE3_CHANNEL_X0Y4 / GTHE3_COMMON_X0Y1 +set_property -dict {LOC AA4 } [get_ports {pcie_tx_p[3]}] ;# MGTHTXN0_225 GTHE3_CHANNEL_X0Y4 / GTHE3_COMMON_X0Y1 +#set_property -dict {LOC AA3 } [get_ports {pcie_tx_n[3]}] ;# MGTHTXP0_225 GTHE3_CHANNEL_X0Y4 / GTHE3_COMMON_X0Y1 +set_property -dict {LOC V2 } [get_ports {pcie_rx_p[2]}] ;# MGTHTXN1_225 GTHE3_CHANNEL_X0Y5 / GTHE3_COMMON_X0Y1 +#set_property -dict {LOC V1 } [get_ports {pcie_rx_n[2]}] ;# MGTHTXP1_225 GTHE3_CHANNEL_X0Y5 / GTHE3_COMMON_X0Y1 +set_property -dict {LOC W4 } [get_ports {pcie_tx_p[2]}] ;# MGTHTXN1_225 GTHE3_CHANNEL_X0Y5 / GTHE3_COMMON_X0Y1 +#set_property -dict {LOC W3 } [get_ports {pcie_tx_n[2]}] ;# MGTHTXP1_225 GTHE3_CHANNEL_X0Y5 / GTHE3_COMMON_X0Y1 +set_property -dict {LOC T2 } [get_ports {pcie_rx_p[1]}] ;# MGTHTXN2_225 GTHE3_CHANNEL_X0Y6 / GTHE3_COMMON_X0Y1 +#set_property -dict {LOC T1 } [get_ports {pcie_rx_n[1]}] ;# MGTHTXP2_225 GTHE3_CHANNEL_X0Y6 / GTHE3_COMMON_X0Y1 +set_property -dict {LOC U4 } [get_ports {pcie_tx_p[1]}] ;# MGTHTXN2_225 GTHE3_CHANNEL_X0Y6 / GTHE3_COMMON_X0Y1 +#set_property -dict {LOC U3 } [get_ports {pcie_tx_n[1]}] ;# MGTHTXP2_225 GTHE3_CHANNEL_X0Y6 / GTHE3_COMMON_X0Y1 +set_property -dict {LOC P2 } [get_ports {pcie_rx_p[0]}] ;# MGTHTXN3_225 GTHE3_CHANNEL_X0Y7 / GTHE3_COMMON_X0Y1 +#set_property -dict {LOC P1 } [get_ports {pcie_rx_n[0]}] ;# MGTHTXP3_225 GTHE3_CHANNEL_X0Y7 / GTHE3_COMMON_X0Y1 +set_property -dict {LOC R4 } [get_ports {pcie_tx_p[0]}] ;# MGTHTXN3_225 GTHE3_CHANNEL_X0Y7 / GTHE3_COMMON_X0Y1 +#set_property -dict {LOC R3 } [get_ports {pcie_tx_n[0]}] ;# MGTHTXP3_225 GTHE3_CHANNEL_X0Y7 / GTHE3_COMMON_X0Y1 +set_property -dict {LOC T6 } [get_ports pcie_mgt_refclk_p] ;# MGTREFCLK0P_225 +#set_property -dict {LOC T5 } [get_ports pcie_mgt_refclk_n] ;# MGTREFCLK0N_225 +set_property -dict {LOC AC22 IOSTANDARD LVCMOS18 PULLUP true} [get_ports pcie_reset_n] + +# 100 MHz MGT reference clock +create_clock -period 10 -name pcie_mgt_refclk [get_ports pcie_mgt_refclk_p] + +# Flash +#set_property -dict {LOC AE10 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[0]}] +#set_property -dict {LOC AC8 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[1]}] +#set_property -dict {LOC AD10 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[2]}] +#set_property -dict {LOC AD9 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[3]}] +#set_property -dict {LOC AC11 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[4]}] +#set_property -dict {LOC AF10 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[5]}] +#set_property -dict {LOC AF14 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[6]}] +#set_property -dict {LOC AE12 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[7]}] +#set_property -dict {LOC AD14 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[8]}] +#set_property -dict {LOC AF13 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[9]}] +#set_property -dict {LOC AE13 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[10]}] +#set_property -dict {LOC AD8 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[11]}] +#set_property -dict {LOC AC13 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[12]}] +#set_property -dict {LOC AD13 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[13]}] +#set_property -dict {LOC AA14 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[14]}] +#set_property -dict {LOC AB15 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_dq[15]}] +#set_property -dict {LOC AD11 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[0]}] +#set_property -dict {LOC AE11 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[1]}] +#set_property -dict {LOC AF12 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[2]}] +#set_property -dict {LOC AB11 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[3]}] +#set_property -dict {LOC AB9 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[4]}] +#set_property -dict {LOC AB14 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[5]}] +#set_property -dict {LOC AA10 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[6]}] +#set_property -dict {LOC AA9 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[7]}] +#set_property -dict {LOC W10 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[8]}] +#set_property -dict {LOC AA13 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[9]}] +#set_property -dict {LOC Y15 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[10]}] +#set_property -dict {LOC AC12 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[11]}] +#set_property -dict {LOC V12 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[12]}] +#set_property -dict {LOC V11 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[13]}] +#set_property -dict {LOC Y12 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[14]}] +#set_property -dict {LOC W9 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[15]}] +#set_property -dict {LOC Y8 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[16]}] +#set_property -dict {LOC W8 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[17]}] +#set_property -dict {LOC W15 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[18]}] +#set_property -dict {LOC AA15 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[19]}] +#set_property -dict {LOC AE16 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[20]}] +#set_property -dict {LOC AF15 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[21]}] +#set_property -dict {LOC AE15 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_addr[22]}] +#set_property -dict {LOC AD15 IOSTANDARD LVCMOS18 PULLUP true} [get_ports {flash_region}] +#set_property -dict {LOC AC9 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_ce_n}] +#set_property -dict {LOC AC14 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_oe_n}] +#set_property -dict {LOC AB10 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_we_n}] +#set_property -dict {LOC Y10 IOSTANDARD LVCMOS18 DRIVE 16} [get_ports {flash_adv_n}] + diff --git a/example/ExaNIC_X10/fpga/fpga/Makefile b/example/ExaNIC_X10/fpga/fpga/Makefile new file mode 100644 index 0000000..84476e6 --- /dev/null +++ b/example/ExaNIC_X10/fpga/fpga/Makefile @@ -0,0 +1,87 @@ + +# FPGA settings +FPGA_PART = xcku035-fbva676-2-e +FPGA_TOP = fpga +FPGA_ARCH = kintexu + +# Files for synthesis +SYN_FILES = rtl/fpga.v +SYN_FILES += rtl/fpga_core.v +SYN_FILES += rtl/debounce_switch.v +SYN_FILES += rtl/sync_reset.v +SYN_FILES += rtl/sync_signal.v +SYN_FILES += rtl/axi_ram.v +SYN_FILES += rtl/axis_register.v +SYN_FILES += lib/pcie/rtl/axis_arb_mux.v +SYN_FILES += lib/pcie/rtl/pcie_us_axil_master.v +SYN_FILES += lib/pcie/rtl/pcie_us_axi_dma.v +SYN_FILES += lib/pcie/rtl/pcie_us_axi_dma_rd.v +SYN_FILES += lib/pcie/rtl/pcie_us_axi_dma_wr.v +SYN_FILES += lib/pcie/rtl/pcie_tag_manager.v +SYN_FILES += lib/pcie/rtl/pcie_us_axi_master.v +SYN_FILES += lib/pcie/rtl/pcie_us_axi_master_rd.v +SYN_FILES += lib/pcie/rtl/pcie_us_axi_master_wr.v +SYN_FILES += lib/pcie/rtl/pcie_us_axis_cq_demux.v +SYN_FILES += lib/pcie/rtl/pcie_us_cfg.v +SYN_FILES += lib/pcie/rtl/pcie_us_msi.v +SYN_FILES += lib/pcie/rtl/arbiter.v +SYN_FILES += lib/pcie/rtl/priority_encoder.v +SYN_FILES += lib/pcie/rtl/pulse_merge.v + +# XDC files +XDC_FILES = fpga.xdc + +# IP +XCI_FILES = ip/pcie3_ultrascale_0.xci + +include ../common/vivado.mk + +program: $(FPGA_TOP).bit + echo "open_hw" > program.tcl + echo "connect_hw_server" >> program.tcl + echo "open_hw_target" >> program.tcl + echo "current_hw_device [lindex [get_hw_devices] 0]" >> program.tcl + echo "refresh_hw_device -update_hw_probes false [current_hw_device]" >> program.tcl + echo "set_property PROGRAM.FILE {$(FPGA_TOP).bit} [current_hw_device]" >> program.tcl + echo "program_hw_devices [current_hw_device]" >> program.tcl + echo "exit" >> program.tcl + vivado -nojournal -nolog -mode batch -source program.tcl + +%.mcs %.prm: %.bit + echo "write_cfgmem -force -format mcs -size 32 -interface BPIx16 -loadbit {up 0x0000000 $*.bit} -checksum -file $*.mcs" > generate_mcs.tcl + echo "exit" >> generate_mcs.tcl + vivado -nojournal -nolog -mode batch -source generate_mcs.tcl + mkdir -p rev + COUNT=100; \ + while [ -e rev/$*_rev$$COUNT.bit ]; \ + do COUNT=$$((COUNT+1)); done; \ + COUNT=$$((COUNT-1)); \ + for x in .mcs .prm; \ + do cp $*$$x rev/$*_rev$$COUNT$$x; \ + echo "Output: rev/$*_rev$$COUNT$$x"; done; + +flash: $(FPGA_TOP).mcs $(FPGA_TOP).prm + echo "open_hw" > flash.tcl + echo "connect_hw_server" >> flash.tcl + echo "open_hw_target" >> flash.tcl + echo "current_hw_device [lindex [get_hw_devices] 0]" >> flash.tcl + echo "refresh_hw_device -update_hw_probes false [current_hw_device]" >> flash.tcl + echo "create_hw_cfgmem -hw_device [current_hw_device] [lindex [get_cfgmem_parts {28f256p30t-bpi-x16}] 0]" >> flash.tcl + echo "current_hw_cfgmem -hw_device [current_hw_device] [get_property PROGRAM.HW_CFGMEM [current_hw_device]]" >> flash.tcl + echo "set_property PROGRAM.FILES [list \"$(FPGA_TOP).mcs\"] [current_hw_cfgmem]" >> flash.tcl + echo "set_property PROGRAM.PRM_FILES [list \"$(FPGA_TOP).prm\"] [current_hw_cfgmem]" >> flash.tcl + echo "set_property PROGRAM.ERASE 1 [current_hw_cfgmem]" >> flash.tcl + echo "set_property PROGRAM.CFG_PROGRAM 1 [current_hw_cfgmem]" >> flash.tcl + echo "set_property PROGRAM.VERIFY 1 [current_hw_cfgmem]" >> flash.tcl + echo "set_property PROGRAM.CHECKSUM 0 [current_hw_cfgmem]" >> flash.tcl + echo "set_property PROGRAM.ADDRESS_RANGE {use_file} [current_hw_cfgmem]" >> flash.tcl + echo "set_property PROGRAM.BPI_RS_PINS {none} [current_hw_cfgmem]" >> flash.tcl + echo "set_property PROGRAM.UNUSED_PIN_TERMINATION {pull-none} [current_hw_cfgmem]" >> flash.tcl + echo "create_hw_bitstream -hw_device [current_hw_device] [get_property PROGRAM.HW_CFGMEM_BITFILE [current_hw_device]]" >> flash.tcl + echo "program_hw_devices [current_hw_device]" >> flash.tcl + echo "refresh_hw_device [current_hw_device]" >> flash.tcl + echo "program_hw_cfgmem -hw_cfgmem [current_hw_cfgmem]" >> flash.tcl + echo "boot_hw_device [current_hw_device]" >> flash.tcl + echo "exit" >> flash.tcl + vivado -nojournal -nolog -mode batch -source flash.tcl + diff --git a/example/ExaNIC_X10/fpga/ip/pcie3_ultrascale_0.xci b/example/ExaNIC_X10/fpga/ip/pcie3_ultrascale_0.xci new file mode 100644 index 0000000..0e872a8 --- /dev/null +++ b/example/ExaNIC_X10/fpga/ip/pcie3_ultrascale_0.xci @@ -0,0 +1,899 @@ + + + xilinx.com + xci + unknown + 1.0 + + + pcie3_ultrascale_0 + + + + + + 100000000 + 0 + 0.000 + + + + 100000000 + 0 + 0.000 + + 0 + 0.000 + + 100000000 + 1 + 1 + 1 + 0 + 0 + undef + 0.000 + 32 + 0 + 0 + 85 + + 100000000 + 1 + 1 + 1 + 0 + 0 + undef + 0.000 + 32 + 0 + 0 + 75 + 0 + ACTIVE_LOW + 0 + + 100000000 + 1 + 1 + 1 + 0 + 0 + undef + 0.000 + 32 + 0 + 0 + 33 + + 100000000 + 1 + 1 + 1 + 0 + 0 + undef + 0.000 + 32 + 0 + 0 + 60 + 0x000 + FALSE + FALSE + FALSE + FALSE + FALSE + TRUE + 0x00000 + FALSE + FALSE + FALSE + FALSE + FALSE + FALSE + TRUE + TRUE + TRUE + TRUE + TRUE + TRUE + 16KB + 2 + 256 + FALSE + TRUE + 0 + FALSE + FALSE + FALSE + FALSE + FALSE + FALSE + FALSE + FALSE + FALSE + 0 + 1 + 0 + Add-in_Card + 0x000 + NONE + 0x00000000 + FALSE + TRUE + FALSE + FALSE + FALSE + NONE + 3 + 2.0 + TRUE + FALSE + FALSE + 0x300 + 0x000 + 0x00 + 0x11 + 0x4 + 0x11 + 0x4 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x80 + 0x020000 + 0x0001 + FALSE + FALSE + FALSE + FALSE + 0x0 + FALSE + TRUE + FALSE + 0x2 + 0x300 + 0x00 + 0x00 + 0x00 + 0x00 + 0x00 + 0x00 + 0x00 + 0x00 + 0x300 + 0x00 + FALSE + 0x1 + 0 + TRUE + 0x300 + 0x00 + 0 + 0x00000000 + 0 + 0x00000000 + 0x000 + 5 + 0xC0 + 0x274 + 0x90 + FALSE + FALSE + FALSE + FALSE + FALSE + 0x300 + 0x00000 + 0x00000 + 0x00000 + 0x00 + 0x000 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x0000 + 0x300 + 0x0000 + 0x0 + 0x0000 + 0x0000 + 0x00000553 + 0x0000 + 0x0001 + 0x1234 + TRUE + FALSE + FALSE + 0x300 + 0x0 + 0x0 + 0x000 + 0x1 + 0x000 + 0x1234 + FALSE + FALSE + 0x000 + 0x000 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x80 + 0x058000 + 0x8011 + 0x2 + 0x000 + 0x00 + 0x00 + 0x00 + 0x00 + 0x00 + 0x00 + 0x00 + 0x00 + 0x000 + 0x00 + FALSE + 0x0 + 0x00 + 0 + 0x00000000 + 0 + 0x00000000 + 0x000 + 0 + 0x00 + 0x000 + 0x00 + FALSE + 0x000 + 0x00000 + 0x00000 + 0x00000 + 0x00 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x00 + 0x0 + 0x0000 + 0x000 + 0x0000 + 0x0 + 0x0000 + 0x0001 + 0x00000553 + 0x0000 + 0x0007 + TRUE + FALSE + FALSE + 0x000 + 0x0 + 0x0 + 0x000 + 0x1 + 4 + FALSE + 2 + FALSE + 4 + 8 + TRUE + FALSE + TRUE + 0 + 0 + GTH_Quad_225 + 1 + 0x00000000 + FALSE + 0 + 0x000 + 0x00 + 0x028 + 0x20 + 0x198 + 0x20 + FALSE + FALSE + 0x0 + FALSE + TRUE + 3 + 0x000 + 0x80 + 0 + 0x00000000 + 0 + 0x00000000 + 0x000 + 0 + 0x00 + TRUE + FALSE + 0x000 + 0x0 + 0x0 + 0x000 + 0x1 + 0x000 + 0 + 0x00000000 + 0 + 0x00000000 + 0x000 + 0 + 0x00 + TRUE + FALSE + 0x000 + 0x0 + 0x0 + 0x000 + 0x1 + 0x000 + 0 + 0x00000000 + 0 + 0x00000000 + 0x000 + 0 + 0x00 + TRUE + FALSE + 0x000 + 0x0 + 0x0 + 0x000 + 0x1 + 0x000 + 0 + 0x00000000 + 0 + 0x00000000 + 0x000 + 0 + 0x00 + TRUE + FALSE + 0x000 + 0x0 + 0x0 + 0x000 + 0x1 + 0x000 + 0 + 0x00000000 + 0 + 0x00000000 + 0x000 + 0 + 0x00 + TRUE + FALSE + 0x000 + 0x0 + 0x0 + 0x000 + 0x1 + 0x000 + 0 + 0x00000000 + 0 + 0x00000000 + 0x000 + 0 + 0x00 + TRUE + FALSE + 0x000 + 0x0 + 0x0 + 0x000 + 0x1 + FALSE + 1 + 0 + 0 + 0 + 0 + 0 + 0 + Production + 0 + true + false + pcie3_ultrascale_0 + 15 + false + false + 020000 + 0001 + false + false + false + 00_Not_Supported + false + false + INTA + true + BAR_0 + 00000000 + BAR_0 + 00000000 + 000 + 32_vectors + false + false + false + false + 00 + 0 + N/A + 0000 + 00000553 + 0000 + 0001 + 1234 + false + false + false + 058000 + 8011 + NONE + BAR_0 + 00000000 + BAR_0 + 00000000 + 000 + 1_vector + 00 + 0 + 0 + N/A + 0001 + 00000553 + 0000 + 0007 + false + 4 + 8.0_GT/s + X8 + 100_MHz + Default + 0 + 0 + false + false + 1 + false + BAR_0 + 00000000 + BAR_0 + 00000000 + 000 + 1_vector + BAR_0 + 00000000 + BAR_0 + 00000000 + 000 + 1_vector + BAR_0 + 00000000 + BAR_0 + 00000000 + 000 + 1_vector + BAR_0 + 00000000 + BAR_0 + 00000000 + 000 + 1_vector + BAR_0 + 00000000 + BAR_0 + 00000000 + 000 + 1_vector + BAR_0 + 00000000 + BAR_0 + 00000000 + 000 + 1_vector + false + DWORD_Aligned + No_ASPM + 250 + true + 2FFFF + false + false + 256_bit + false + None + true + true + true + true + true + true + 500 + true + PCI_Express_Endpoint_device + false + false + false + false + true + false + false + false + false + false + false + false + false + False + false + false + false + false + false + false + true + 100_MHz + true + false + false + false + false + false + Internal + 1 + Add-in_Card + None + 00000000 + Basic + false + X0Y0 + true + Extreme + false + true + false + false + true + false + Megabytes + 16 + Memory + false + true + false + Megabytes + 16 + Memory + false + false + false + Kilobytes + 2 + N/A + false + false + false + Kilobytes + 2 + N/A + false + false + false + Kilobytes + 2 + N/A + false + false + Kilobytes + 2 + N/A + Network_controller + 02 + 00 + 00 + 512_bytes + false + false + false + Kilobytes + 2 + false + true + false + false + false + false + true + false + Kilobytes + 2 + Memory + false + false + false + Kilobytes + 2 + N/A + false + false + false + Kilobytes + 2 + N/A + false + false + false + Kilobytes + 2 + N/A + false + false + false + Kilobytes + 2 + N/A + false + false + Kilobytes + 2 + N/A + 0 + Ethernet_controller + false + false + true + false + false + false + false + Kilobytes + 2 + N/A + false + false + false + Kilobytes + 2 + N/A + false + false + false + Kilobytes + 2 + N/A + false + false + false + Kilobytes + 2 + N/A + false + false + false + Kilobytes + 2 + N/A + false + false + Kilobytes + 2 + N/A + Memory_controller + 05 + 00 + 80 + 512_bytes + false + false + false + Kilobytes + 2 + true + false + false + false + false + true + false + Kilobytes + 2 + Memory + false + false + false + Kilobytes + 2 + N/A + false + false + false + Kilobytes + 2 + N/A + false + false + false + Kilobytes + 2 + N/A + false + false + false + Kilobytes + 2 + N/A + false + false + Kilobytes + 2 + N/A + Other_memory_controller + false + false + QPLL1 + None + true + GTH_Quad_225 + false + ACTIVE_LOW + None + true + true + 1234 + None + kintexu + + + xcku035 + fbva676 + VERILOG + + MIXED + -2 + + E + TRUE + TRUE + IP_Flow + 5 + TRUE + . + + . + 2019.1 + OUT_OF_CONTEXT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/ExaNIC_X10/fpga/lib/pcie b/example/ExaNIC_X10/fpga/lib/pcie new file mode 120000 index 0000000..11a54ed --- /dev/null +++ b/example/ExaNIC_X10/fpga/lib/pcie @@ -0,0 +1 @@ +../../../../ \ No newline at end of file diff --git a/example/ExaNIC_X10/fpga/rtl/axi_ram.v b/example/ExaNIC_X10/fpga/rtl/axi_ram.v new file mode 100644 index 0000000..2ec9d04 --- /dev/null +++ b/example/ExaNIC_X10/fpga/rtl/axi_ram.v @@ -0,0 +1,365 @@ +/* + +Copyright (c) 2018 Alex Forencich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +// Language: Verilog 2001 + +`timescale 1ns / 1ps + +/* + * AXI4 RAM + */ +module axi_ram # +( + parameter DATA_WIDTH = 32, // width of data bus in bits + parameter ADDR_WIDTH = 16, // width of address bus in bits + parameter STRB_WIDTH = (DATA_WIDTH/8), + parameter ID_WIDTH = 8, + parameter PIPELINE_OUTPUT = 0 +) +( + input wire clk, + input wire rst, + + input wire [ID_WIDTH-1:0] s_axi_awid, + input wire [ADDR_WIDTH-1:0] s_axi_awaddr, + input wire [7:0] s_axi_awlen, + input wire [2:0] s_axi_awsize, + input wire [1:0] s_axi_awburst, + input wire s_axi_awlock, + input wire [3:0] s_axi_awcache, + input wire [2:0] s_axi_awprot, + input wire s_axi_awvalid, + output wire s_axi_awready, + input wire [DATA_WIDTH-1:0] s_axi_wdata, + input wire [STRB_WIDTH-1:0] s_axi_wstrb, + input wire s_axi_wlast, + input wire s_axi_wvalid, + output wire s_axi_wready, + output wire [ID_WIDTH-1:0] s_axi_bid, + output wire [1:0] s_axi_bresp, + output wire s_axi_bvalid, + input wire s_axi_bready, + input wire [ID_WIDTH-1:0] s_axi_arid, + input wire [ADDR_WIDTH-1:0] s_axi_araddr, + input wire [7:0] s_axi_arlen, + input wire [2:0] s_axi_arsize, + input wire [1:0] s_axi_arburst, + input wire s_axi_arlock, + input wire [3:0] s_axi_arcache, + input wire [2:0] s_axi_arprot, + input wire s_axi_arvalid, + output wire s_axi_arready, + output wire [ID_WIDTH-1:0] s_axi_rid, + output wire [DATA_WIDTH-1:0] s_axi_rdata, + output wire [1:0] s_axi_rresp, + output wire s_axi_rlast, + output wire s_axi_rvalid, + input wire s_axi_rready +); + +parameter VALID_ADDR_WIDTH = ADDR_WIDTH - $clog2(STRB_WIDTH); +parameter WORD_WIDTH = STRB_WIDTH; +parameter WORD_SIZE = DATA_WIDTH/WORD_WIDTH; + +// bus width assertions +initial begin + if (WORD_SIZE * STRB_WIDTH != DATA_WIDTH) begin + $error("Error: AXI data width not evenly divisble"); + $finish; + end + + if (2**$clog2(WORD_WIDTH) != WORD_WIDTH) begin + $error("Error: AXI word width must be even power of two"); + $finish; + end +end + +localparam [0:0] + READ_STATE_IDLE = 1'd0, + READ_STATE_BURST = 1'd1; + +reg [0:0] read_state_reg = READ_STATE_IDLE, read_state_next; + +localparam [1:0] + WRITE_STATE_IDLE = 2'd0, + WRITE_STATE_BURST = 2'd1, + WRITE_STATE_RESP = 2'd2; + +reg [1:0] write_state_reg = WRITE_STATE_IDLE, write_state_next; + +reg mem_wr_en; +reg mem_rd_en; + +reg [ID_WIDTH-1:0] read_id_reg = {ID_WIDTH{1'b0}}, read_id_next; +reg [ADDR_WIDTH-1:0] read_addr_reg = {ADDR_WIDTH{1'b0}}, read_addr_next; +reg [7:0] read_count_reg = 8'd0, read_count_next; +reg [2:0] read_size_reg = 3'd0, read_size_next; +reg [1:0] read_burst_reg = 2'd0, read_burst_next; +reg [ID_WIDTH-1:0] write_id_reg = {ID_WIDTH{1'b0}}, write_id_next; +reg [ADDR_WIDTH-1:0] write_addr_reg = {ADDR_WIDTH{1'b0}}, write_addr_next; +reg [7:0] write_count_reg = 8'd0, write_count_next; +reg [2:0] write_size_reg = 3'd0, write_size_next; +reg [1:0] write_burst_reg = 2'd0, write_burst_next; + +reg s_axi_awready_reg = 1'b0, s_axi_awready_next; +reg s_axi_wready_reg = 1'b0, s_axi_wready_next; +reg [ID_WIDTH-1:0] s_axi_bid_reg = {ID_WIDTH{1'b0}}, s_axi_bid_next; +reg s_axi_bvalid_reg = 1'b0, s_axi_bvalid_next; +reg s_axi_arready_reg = 1'b0, s_axi_arready_next; +reg [ID_WIDTH-1:0] s_axi_rid_reg = {ID_WIDTH{1'b0}}, s_axi_rid_next; +reg [DATA_WIDTH-1:0] s_axi_rdata_reg = {DATA_WIDTH{1'b0}}, s_axi_rdata_next; +reg s_axi_rlast_reg = 1'b0, s_axi_rlast_next; +reg s_axi_rvalid_reg = 1'b0, s_axi_rvalid_next; +reg [ID_WIDTH-1:0] s_axi_rid_pipe_reg = {ID_WIDTH{1'b0}}; +reg [DATA_WIDTH-1:0] s_axi_rdata_pipe_reg = {DATA_WIDTH{1'b0}}; +reg s_axi_rlast_pipe_reg = 1'b0; +reg s_axi_rvalid_pipe_reg = 1'b0; + +// (* RAM_STYLE="BLOCK" *) +reg [DATA_WIDTH-1:0] mem[(2**VALID_ADDR_WIDTH)-1:0]; + +wire [VALID_ADDR_WIDTH-1:0] s_axi_awaddr_valid = s_axi_awaddr >> (ADDR_WIDTH - VALID_ADDR_WIDTH); +wire [VALID_ADDR_WIDTH-1:0] s_axi_araddr_valid = s_axi_araddr >> (ADDR_WIDTH - VALID_ADDR_WIDTH); +wire [VALID_ADDR_WIDTH-1:0] read_addr_valid = read_addr_reg >> (ADDR_WIDTH - VALID_ADDR_WIDTH); +wire [VALID_ADDR_WIDTH-1:0] write_addr_valid = write_addr_reg >> (ADDR_WIDTH - VALID_ADDR_WIDTH); + +assign s_axi_awready = s_axi_awready_reg; +assign s_axi_wready = s_axi_wready_reg; +assign s_axi_bid = s_axi_bid_reg; +assign s_axi_bresp = 2'b00; +assign s_axi_bvalid = s_axi_bvalid_reg; +assign s_axi_arready = s_axi_arready_reg; +assign s_axi_rid = PIPELINE_OUTPUT ? s_axi_rid_pipe_reg : s_axi_rid_reg; +assign s_axi_rdata = PIPELINE_OUTPUT ? s_axi_rdata_pipe_reg : s_axi_rdata_reg; +assign s_axi_rresp = 2'b00; +assign s_axi_rlast = PIPELINE_OUTPUT ? s_axi_rlast_pipe_reg : s_axi_rlast_reg; +assign s_axi_rvalid = PIPELINE_OUTPUT ? s_axi_rvalid_pipe_reg : s_axi_rvalid_reg; + +integer i, j; + +initial begin + // two nested loops for smaller number of iterations per loop + // workaround for synthesizer complaints about large loop counts + for (i = 0; i < 2**ADDR_WIDTH; i = i + 2**(ADDR_WIDTH/2)) begin + for (j = i; j < i + 2**(ADDR_WIDTH/2); j = j + 1) begin + mem[j] = 0; + end + end +end + +always @* begin + write_state_next = WRITE_STATE_IDLE; + + mem_wr_en = 1'b0; + + write_id_next = write_id_reg; + write_addr_next = write_addr_reg; + write_count_next = write_count_reg; + write_size_next = write_size_reg; + write_burst_next = write_burst_reg; + + s_axi_awready_next = 1'b0; + s_axi_wready_next = 1'b0; + s_axi_bid_next = s_axi_bid_reg; + s_axi_bvalid_next = s_axi_bvalid_reg && !s_axi_bready; + + case (write_state_reg) + WRITE_STATE_IDLE: begin + s_axi_awready_next = 1'b1; + + if (s_axi_awready && s_axi_awvalid) begin + write_id_next = s_axi_awid; + write_addr_next = s_axi_awaddr; + write_count_next = s_axi_awlen; + write_size_next = s_axi_awsize < $clog2(STRB_WIDTH) ? s_axi_awsize : $clog2(STRB_WIDTH); + write_burst_next = s_axi_awburst; + + s_axi_awready_next = 1'b0; + s_axi_wready_next = 1'b1; + write_state_next = WRITE_STATE_BURST; + end else begin + write_state_next = WRITE_STATE_IDLE; + end + end + WRITE_STATE_BURST: begin + s_axi_wready_next = 1'b1; + + if (s_axi_wready && s_axi_wvalid) begin + mem_wr_en = 1'b1; + if (write_burst_reg != 2'b00) begin + write_addr_next = write_addr_reg + (1 << write_size_reg); + end + write_count_next = write_count_reg - 1; + if (write_count_reg > 0) begin + write_state_next = WRITE_STATE_BURST; + end else begin + s_axi_wready_next = 1'b0; + if (s_axi_bready || !s_axi_bvalid) begin + s_axi_bid_next = write_id_reg; + s_axi_bvalid_next = 1'b1; + s_axi_awready_next = 1'b1; + write_state_next = WRITE_STATE_IDLE; + end else begin + write_state_next = WRITE_STATE_RESP; + end + end + end else begin + write_state_next = WRITE_STATE_BURST; + end + end + WRITE_STATE_RESP: begin + if (s_axi_bready || !s_axi_bvalid) begin + s_axi_bid_next = write_id_reg; + s_axi_bvalid_next = 1'b1; + s_axi_awready_next = 1'b1; + write_state_next = WRITE_STATE_IDLE; + end else begin + write_state_next = WRITE_STATE_RESP; + end + end + endcase +end + +always @(posedge clk) begin + if (rst) begin + write_state_reg <= WRITE_STATE_IDLE; + s_axi_awready_reg <= 1'b0; + s_axi_wready_reg <= 1'b0; + s_axi_bvalid_reg <= 1'b0; + end else begin + write_state_reg <= write_state_next; + s_axi_awready_reg <= s_axi_awready_next; + s_axi_wready_reg <= s_axi_wready_next; + s_axi_bvalid_reg <= s_axi_bvalid_next; + end + + write_id_reg <= write_id_next; + write_addr_reg <= write_addr_next; + write_count_reg <= write_count_next; + write_size_reg <= write_size_next; + write_burst_reg <= write_burst_next; + + s_axi_bid_reg <= s_axi_bid_next; + + for (i = 0; i < WORD_WIDTH; i = i + 1) begin + if (mem_wr_en & s_axi_wstrb[i]) begin + mem[write_addr_valid][WORD_SIZE*i +: WORD_SIZE] <= s_axi_wdata[WORD_SIZE*i +: WORD_SIZE]; + end + end +end + +always @* begin + read_state_next = READ_STATE_IDLE; + + mem_rd_en = 1'b0; + + s_axi_rid_next = s_axi_rid_reg; + s_axi_rlast_next = s_axi_rlast_reg; + s_axi_rvalid_next = s_axi_rvalid_reg && !(s_axi_rready || (PIPELINE_OUTPUT && !s_axi_rvalid_pipe_reg)); + + read_id_next = read_id_reg; + read_addr_next = read_addr_reg; + read_count_next = read_count_reg; + read_size_next = read_size_reg; + read_burst_next = read_burst_reg; + + s_axi_arready_next = 1'b0; + + case (read_state_reg) + READ_STATE_IDLE: begin + s_axi_arready_next = 1'b1; + + if (s_axi_arready && s_axi_arvalid) begin + read_id_next = s_axi_arid; + read_addr_next = s_axi_araddr; + read_count_next = s_axi_arlen; + read_size_next = s_axi_arsize < $clog2(STRB_WIDTH) ? s_axi_arsize : $clog2(STRB_WIDTH); + read_burst_next = s_axi_arburst; + + s_axi_arready_next = 1'b0; + read_state_next = READ_STATE_BURST; + end else begin + read_state_next = READ_STATE_IDLE; + end + end + READ_STATE_BURST: begin + if (s_axi_rready || (PIPELINE_OUTPUT && !s_axi_rvalid_pipe_reg) || !s_axi_rvalid_reg) begin + mem_rd_en = 1'b1; + s_axi_rvalid_next = 1'b1; + s_axi_rid_next = read_id_reg; + s_axi_rlast_next = read_count_reg == 0; + if (read_burst_reg != 2'b00) begin + read_addr_next = read_addr_reg + (1 << read_size_reg); + end + read_count_next = read_count_reg - 1; + if (read_count_reg > 0) begin + read_state_next = READ_STATE_BURST; + end else begin + s_axi_arready_next = 1'b1; + read_state_next = READ_STATE_IDLE; + end + end else begin + read_state_next = READ_STATE_BURST; + end + end + endcase +end + +always @(posedge clk) begin + if (rst) begin + read_state_reg <= READ_STATE_IDLE; + s_axi_arready_reg <= 1'b0; + s_axi_rvalid_reg <= 1'b0; + s_axi_rvalid_pipe_reg <= 1'b0; + end else begin + read_state_reg <= read_state_next; + s_axi_arready_reg <= s_axi_arready_next; + s_axi_rvalid_reg <= s_axi_rvalid_next; + + if (!s_axi_rvalid_pipe_reg || s_axi_rready) begin + s_axi_rvalid_pipe_reg <= s_axi_rvalid_reg; + end + end + + read_id_reg <= read_id_next; + read_addr_reg <= read_addr_next; + read_count_reg <= read_count_next; + read_size_reg <= read_size_next; + read_burst_reg <= read_burst_next; + + s_axi_rid_reg <= s_axi_rid_next; + s_axi_rlast_reg <= s_axi_rlast_next; + + if (mem_rd_en) begin + s_axi_rdata_reg <= mem[read_addr_valid]; + end + + if (!s_axi_rvalid_pipe_reg || s_axi_rready) begin + s_axi_rid_pipe_reg <= s_axi_rid_reg; + s_axi_rdata_pipe_reg <= s_axi_rdata_reg; + s_axi_rlast_pipe_reg <= s_axi_rlast_reg; + end +end + +endmodule diff --git a/example/ExaNIC_X10/fpga/rtl/axis_register.v b/example/ExaNIC_X10/fpga/rtl/axis_register.v new file mode 100644 index 0000000..251bcde --- /dev/null +++ b/example/ExaNIC_X10/fpga/rtl/axis_register.v @@ -0,0 +1,264 @@ +/* + +Copyright (c) 2014-2018 Alex Forencich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +// Language: Verilog 2001 + +`timescale 1ns / 1ps + +/* + * AXI4-Stream register + */ +module axis_register # +( + parameter DATA_WIDTH = 8, + parameter KEEP_ENABLE = (DATA_WIDTH>8), + parameter KEEP_WIDTH = (DATA_WIDTH/8), + parameter LAST_ENABLE = 1, + parameter ID_ENABLE = 0, + parameter ID_WIDTH = 8, + parameter DEST_ENABLE = 0, + parameter DEST_WIDTH = 8, + parameter USER_ENABLE = 1, + parameter USER_WIDTH = 1, + parameter REG_TYPE = 2 +) +( + input wire clk, + input wire rst, + + /* + * AXI Stream input + */ + input wire [DATA_WIDTH-1:0] s_axis_tdata, + input wire [KEEP_WIDTH-1:0] s_axis_tkeep, + input wire s_axis_tvalid, + output wire s_axis_tready, + input wire s_axis_tlast, + input wire [ID_WIDTH-1:0] s_axis_tid, + input wire [DEST_WIDTH-1:0] s_axis_tdest, + input wire [USER_WIDTH-1:0] s_axis_tuser, + + /* + * AXI Stream output + */ + output wire [DATA_WIDTH-1:0] m_axis_tdata, + output wire [KEEP_WIDTH-1:0] m_axis_tkeep, + output wire m_axis_tvalid, + input wire m_axis_tready, + output wire m_axis_tlast, + output wire [ID_WIDTH-1:0] m_axis_tid, + output wire [DEST_WIDTH-1:0] m_axis_tdest, + output wire [USER_WIDTH-1:0] m_axis_tuser +); + +generate + +if (REG_TYPE > 1) begin + // skid buffer, no bubble cycles + + // datapath registers + reg s_axis_tready_reg = 1'b0; + + reg [DATA_WIDTH-1:0] m_axis_tdata_reg = {DATA_WIDTH{1'b0}}; + reg [KEEP_WIDTH-1:0] m_axis_tkeep_reg = {KEEP_WIDTH{1'b0}}; + reg m_axis_tvalid_reg = 1'b0, m_axis_tvalid_next; + reg m_axis_tlast_reg = 1'b0; + reg [ID_WIDTH-1:0] m_axis_tid_reg = {ID_WIDTH{1'b0}}; + reg [DEST_WIDTH-1:0] m_axis_tdest_reg = {DEST_WIDTH{1'b0}}; + reg [USER_WIDTH-1:0] m_axis_tuser_reg = {USER_WIDTH{1'b0}}; + + reg [DATA_WIDTH-1:0] temp_m_axis_tdata_reg = {DATA_WIDTH{1'b0}}; + reg [KEEP_WIDTH-1:0] temp_m_axis_tkeep_reg = {KEEP_WIDTH{1'b0}}; + reg temp_m_axis_tvalid_reg = 1'b0, temp_m_axis_tvalid_next; + reg temp_m_axis_tlast_reg = 1'b0; + reg [ID_WIDTH-1:0] temp_m_axis_tid_reg = {ID_WIDTH{1'b0}}; + reg [DEST_WIDTH-1:0] temp_m_axis_tdest_reg = {DEST_WIDTH{1'b0}}; + reg [USER_WIDTH-1:0] temp_m_axis_tuser_reg = {USER_WIDTH{1'b0}}; + + // datapath control + reg store_axis_input_to_output; + reg store_axis_input_to_temp; + reg store_axis_temp_to_output; + + assign s_axis_tready = s_axis_tready_reg; + + assign m_axis_tdata = m_axis_tdata_reg; + assign m_axis_tkeep = KEEP_ENABLE ? m_axis_tkeep_reg : {KEEP_WIDTH{1'b1}}; + assign m_axis_tvalid = m_axis_tvalid_reg; + assign m_axis_tlast = LAST_ENABLE ? m_axis_tlast_reg : 1'b1; + assign m_axis_tid = ID_ENABLE ? m_axis_tid_reg : {ID_WIDTH{1'b0}}; + assign m_axis_tdest = DEST_ENABLE ? m_axis_tdest_reg : {DEST_WIDTH{1'b0}}; + assign m_axis_tuser = USER_ENABLE ? m_axis_tuser_reg : {USER_WIDTH{1'b0}}; + + // enable ready input next cycle if output is ready or the temp reg will not be filled on the next cycle (output reg empty or no input) + wire s_axis_tready_early = m_axis_tready || (!temp_m_axis_tvalid_reg && (!m_axis_tvalid_reg || !s_axis_tvalid)); + + always @* begin + // transfer sink ready state to source + m_axis_tvalid_next = m_axis_tvalid_reg; + temp_m_axis_tvalid_next = temp_m_axis_tvalid_reg; + + store_axis_input_to_output = 1'b0; + store_axis_input_to_temp = 1'b0; + store_axis_temp_to_output = 1'b0; + + if (s_axis_tready_reg) begin + // input is ready + if (m_axis_tready || !m_axis_tvalid_reg) begin + // output is ready or currently not valid, transfer data to output + m_axis_tvalid_next = s_axis_tvalid; + store_axis_input_to_output = 1'b1; + end else begin + // output is not ready, store input in temp + temp_m_axis_tvalid_next = s_axis_tvalid; + store_axis_input_to_temp = 1'b1; + end + end else if (m_axis_tready) begin + // input is not ready, but output is ready + m_axis_tvalid_next = temp_m_axis_tvalid_reg; + temp_m_axis_tvalid_next = 1'b0; + store_axis_temp_to_output = 1'b1; + end + end + + always @(posedge clk) begin + if (rst) begin + s_axis_tready_reg <= 1'b0; + m_axis_tvalid_reg <= 1'b0; + temp_m_axis_tvalid_reg <= 1'b0; + end else begin + s_axis_tready_reg <= s_axis_tready_early; + m_axis_tvalid_reg <= m_axis_tvalid_next; + temp_m_axis_tvalid_reg <= temp_m_axis_tvalid_next; + end + + // datapath + if (store_axis_input_to_output) begin + m_axis_tdata_reg <= s_axis_tdata; + m_axis_tkeep_reg <= s_axis_tkeep; + m_axis_tlast_reg <= s_axis_tlast; + m_axis_tid_reg <= s_axis_tid; + m_axis_tdest_reg <= s_axis_tdest; + m_axis_tuser_reg <= s_axis_tuser; + end else if (store_axis_temp_to_output) begin + m_axis_tdata_reg <= temp_m_axis_tdata_reg; + m_axis_tkeep_reg <= temp_m_axis_tkeep_reg; + m_axis_tlast_reg <= temp_m_axis_tlast_reg; + m_axis_tid_reg <= temp_m_axis_tid_reg; + m_axis_tdest_reg <= temp_m_axis_tdest_reg; + m_axis_tuser_reg <= temp_m_axis_tuser_reg; + end + + if (store_axis_input_to_temp) begin + temp_m_axis_tdata_reg <= s_axis_tdata; + temp_m_axis_tkeep_reg <= s_axis_tkeep; + temp_m_axis_tlast_reg <= s_axis_tlast; + temp_m_axis_tid_reg <= s_axis_tid; + temp_m_axis_tdest_reg <= s_axis_tdest; + temp_m_axis_tuser_reg <= s_axis_tuser; + end + end + +end else if (REG_TYPE == 1) begin + // simple register, inserts bubble cycles + + // datapath registers + reg s_axis_tready_reg = 1'b0; + + reg [DATA_WIDTH-1:0] m_axis_tdata_reg = {DATA_WIDTH{1'b0}}; + reg [KEEP_WIDTH-1:0] m_axis_tkeep_reg = {KEEP_WIDTH{1'b0}}; + reg m_axis_tvalid_reg = 1'b0, m_axis_tvalid_next; + reg m_axis_tlast_reg = 1'b0; + reg [ID_WIDTH-1:0] m_axis_tid_reg = {ID_WIDTH{1'b0}}; + reg [DEST_WIDTH-1:0] m_axis_tdest_reg = {DEST_WIDTH{1'b0}}; + reg [USER_WIDTH-1:0] m_axis_tuser_reg = {USER_WIDTH{1'b0}}; + + // datapath control + reg store_axis_input_to_output; + + assign s_axis_tready = s_axis_tready_reg; + + assign m_axis_tdata = m_axis_tdata_reg; + assign m_axis_tkeep = KEEP_ENABLE ? m_axis_tkeep_reg : {KEEP_WIDTH{1'b1}}; + assign m_axis_tvalid = m_axis_tvalid_reg; + assign m_axis_tlast = LAST_ENABLE ? m_axis_tlast_reg : 1'b1; + assign m_axis_tid = ID_ENABLE ? m_axis_tid_reg : {ID_WIDTH{1'b0}}; + assign m_axis_tdest = DEST_ENABLE ? m_axis_tdest_reg : {DEST_WIDTH{1'b0}}; + assign m_axis_tuser = USER_ENABLE ? m_axis_tuser_reg : {USER_WIDTH{1'b0}}; + + // enable ready input next cycle if output buffer will be empty + wire s_axis_tready_early = !m_axis_tvalid_next; + + always @* begin + // transfer sink ready state to source + m_axis_tvalid_next = m_axis_tvalid_reg; + + store_axis_input_to_output = 1'b0; + + if (s_axis_tready_reg) begin + m_axis_tvalid_next = s_axis_tvalid; + store_axis_input_to_output = 1'b1; + end else if (m_axis_tready) begin + m_axis_tvalid_next = 1'b0; + end + end + + always @(posedge clk) begin + if (rst) begin + s_axis_tready_reg <= 1'b0; + m_axis_tvalid_reg <= 1'b0; + end else begin + s_axis_tready_reg <= s_axis_tready_early; + m_axis_tvalid_reg <= m_axis_tvalid_next; + end + + // datapath + if (store_axis_input_to_output) begin + m_axis_tdata_reg <= s_axis_tdata; + m_axis_tkeep_reg <= s_axis_tkeep; + m_axis_tlast_reg <= s_axis_tlast; + m_axis_tid_reg <= s_axis_tid; + m_axis_tdest_reg <= s_axis_tdest; + m_axis_tuser_reg <= s_axis_tuser; + end + end + +end else begin + // bypass + + assign m_axis_tdata = s_axis_tdata; + assign m_axis_tkeep = KEEP_ENABLE ? s_axis_tkeep : {KEEP_WIDTH{1'b1}}; + assign m_axis_tvalid = s_axis_tvalid; + assign m_axis_tlast = LAST_ENABLE ? s_axis_tlast : 1'b1; + assign m_axis_tid = ID_ENABLE ? s_axis_tid : {ID_WIDTH{1'b0}}; + assign m_axis_tdest = DEST_ENABLE ? s_axis_tdest : {DEST_WIDTH{1'b0}}; + assign m_axis_tuser = USER_ENABLE ? s_axis_tuser : {USER_WIDTH{1'b0}}; + + assign s_axis_tready = m_axis_tready; + +end + +endgenerate + +endmodule diff --git a/example/ExaNIC_X10/fpga/rtl/debounce_switch.v b/example/ExaNIC_X10/fpga/rtl/debounce_switch.v new file mode 100644 index 0000000..bb631cc --- /dev/null +++ b/example/ExaNIC_X10/fpga/rtl/debounce_switch.v @@ -0,0 +1,89 @@ +/* + +Copyright (c) 2014-2018 Alex Forencich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +// Language: Verilog-2001 + +`timescale 1 ns / 1 ps + +/* + * Synchronizes switch and button inputs with a slow sampled shift register + */ +module debounce_switch #( + parameter WIDTH=1, // width of the input and output signals + parameter N=3, // length of shift register + parameter RATE=125000 // clock division factor +)( + input wire clk, + input wire rst, + input wire [WIDTH-1:0] in, + output wire [WIDTH-1:0] out +); + +reg [23:0] cnt_reg = 24'd0; + +reg [N-1:0] debounce_reg[WIDTH-1:0]; + +reg [WIDTH-1:0] state; + +/* + * The synchronized output is the state register + */ +assign out = state; + +integer k; + +always @(posedge clk or posedge rst) begin + if (rst) begin + cnt_reg <= 0; + state <= 0; + + for (k = 0; k < WIDTH; k = k + 1) begin + debounce_reg[k] <= 0; + end + end else begin + if (cnt_reg < RATE) begin + cnt_reg <= cnt_reg + 24'd1; + end else begin + cnt_reg <= 24'd0; + end + + if (cnt_reg == 24'd0) begin + for (k = 0; k < WIDTH; k = k + 1) begin + debounce_reg[k] <= {debounce_reg[k][N-2:0], in[k]}; + end + end + + for (k = 0; k < WIDTH; k = k + 1) begin + if (|debounce_reg[k] == 0) begin + state[k] <= 0; + end else if (&debounce_reg[k] == 1) begin + state[k] <= 1; + end else begin + state[k] <= state[k]; + end + end + end +end + +endmodule diff --git a/example/ExaNIC_X10/fpga/rtl/fpga.v b/example/ExaNIC_X10/fpga/rtl/fpga.v new file mode 100644 index 0000000..bda5aff --- /dev/null +++ b/example/ExaNIC_X10/fpga/rtl/fpga.v @@ -0,0 +1,402 @@ +/* + +Copyright (c) 2018 Alex Forencich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +// Language: Verilog 2001 + +`timescale 1ns / 1ps + +/* + * FPGA top-level module + */ +module fpga ( + /* + * GPIO + */ + output wire [1:0] sfp_1_led, + output wire [1:0] sfp_2_led, + output wire [1:0] sma_led, + + /* + * PCI express + */ + input wire [7:0] pcie_rx_p, + input wire [7:0] pcie_rx_n, + output wire [7:0] pcie_tx_p, + output wire [7:0] pcie_tx_n, + input wire pcie_mgt_refclk_p, + input wire pcie_mgt_refclk_n, + input wire pcie_reset_n +); + +parameter AXIS_PCIE_DATA_WIDTH = 256; +parameter AXIS_PCIE_KEEP_WIDTH = (AXIS_PCIE_DATA_WIDTH/32); + +// PCIe +wire pcie_user_clk; +wire pcie_user_reset; + +wire pcie_sys_clk; +wire pcie_sys_clk_gt; + +IBUFDS_GTE3 #( + .REFCLK_HROW_CK_SEL(2'b00) +) +ibufds_gte3_pcie_mgt_refclk_inst ( + .I (pcie_mgt_refclk_p), + .IB (pcie_mgt_refclk_n), + .CEB (1'b0), + .O (pcie_sys_clk_gt), + .ODIV2 (pcie_sys_clk) +); + +wire [AXIS_PCIE_DATA_WIDTH-1:0] axis_rq_tdata; +wire [AXIS_PCIE_KEEP_WIDTH-1:0] axis_rq_tkeep; +wire axis_rq_tlast; +wire axis_rq_tready; +wire [59:0] axis_rq_tuser; +wire axis_rq_tvalid; + +wire [AXIS_PCIE_DATA_WIDTH-1:0] axis_rc_tdata; +wire [AXIS_PCIE_KEEP_WIDTH-1:0] axis_rc_tkeep; +wire axis_rc_tlast; +wire axis_rc_tready; +wire [74:0] axis_rc_tuser; +wire axis_rc_tvalid; + +wire [AXIS_PCIE_DATA_WIDTH-1:0] axis_cq_tdata; +wire [AXIS_PCIE_KEEP_WIDTH-1:0] axis_cq_tkeep; +wire axis_cq_tlast; +wire axis_cq_tready; +wire [84:0] axis_cq_tuser; +wire axis_cq_tvalid; + +wire [AXIS_PCIE_DATA_WIDTH-1:0] axis_cc_tdata; +wire [AXIS_PCIE_KEEP_WIDTH-1:0] axis_cc_tkeep; +wire axis_cc_tlast; +wire axis_cc_tready; +wire [32:0] axis_cc_tuser; +wire axis_cc_tvalid; + +// ila_0 rq_ila ( +// .clk(pcie_user_clk), +// .probe0(axis_rq_tdata), +// .probe1(axis_rq_tkeep), +// .probe2(axis_rq_tlast), +// .probe3(axis_rq_tready), +// .probe4(axis_rq_tuser), +// .probe5(axis_rq_tvalid) +// ); + +// ila_0 rc_ila ( +// .clk(pcie_user_clk), +// .probe0(axis_rc_tdata), +// .probe1(axis_rc_tkeep), +// .probe2(axis_rc_tlast), +// .probe3(axis_rc_tready), +// .probe4(axis_rc_tuser), +// .probe5(axis_rc_tvalid) +// ); + +wire [2:0] cfg_max_payload; +wire [2:0] cfg_max_read_req; + +wire [18:0] cfg_mgmt_addr; +wire cfg_mgmt_write; +wire [31:0] cfg_mgmt_write_data; +wire [3:0] cfg_mgmt_byte_enable; +wire cfg_mgmt_read; +wire [31:0] cfg_mgmt_read_data; +wire cfg_mgmt_read_write_done; + +wire [3:0] cfg_interrupt_msi_enable; +wire [7:0] cfg_interrupt_msi_vf_enable; +wire [11:0] cfg_interrupt_msi_mmenable; +wire cfg_interrupt_msi_mask_update; +wire [31:0] cfg_interrupt_msi_data; +wire [3:0] cfg_interrupt_msi_select; +wire [31:0] cfg_interrupt_msi_int; +wire [31:0] cfg_interrupt_msi_pending_status; +wire cfg_interrupt_msi_pending_status_data_enable; +wire [3:0] cfg_interrupt_msi_pending_status_function_num; +wire cfg_interrupt_msi_sent; +wire cfg_interrupt_msi_fail; +wire [2:0] cfg_interrupt_msi_attr; +wire cfg_interrupt_msi_tph_present; +wire [1:0] cfg_interrupt_msi_tph_type; +wire [8:0] cfg_interrupt_msi_tph_st_tag; +wire [3:0] cfg_interrupt_msi_function_number; + +wire status_error_cor; +wire status_error_uncor; + +pcie3_ultrascale_0 +pcie3_ultrascale_inst ( + .pci_exp_txn(pcie_tx_n), + .pci_exp_txp(pcie_tx_p), + .pci_exp_rxn(pcie_rx_n), + .pci_exp_rxp(pcie_rx_p), + .user_clk(pcie_user_clk), + .user_reset(pcie_user_reset), + .user_lnk_up(), + + .s_axis_rq_tdata(axis_rq_tdata), + .s_axis_rq_tkeep(axis_rq_tkeep), + .s_axis_rq_tlast(axis_rq_tlast), + .s_axis_rq_tready(axis_rq_tready), + .s_axis_rq_tuser(axis_rq_tuser), + .s_axis_rq_tvalid(axis_rq_tvalid), + + .m_axis_rc_tdata(axis_rc_tdata), + .m_axis_rc_tkeep(axis_rc_tkeep), + .m_axis_rc_tlast(axis_rc_tlast), + .m_axis_rc_tready(axis_rc_tready), + .m_axis_rc_tuser(axis_rc_tuser), + .m_axis_rc_tvalid(axis_rc_tvalid), + + .m_axis_cq_tdata(axis_cq_tdata), + .m_axis_cq_tkeep(axis_cq_tkeep), + .m_axis_cq_tlast(axis_cq_tlast), + .m_axis_cq_tready(axis_cq_tready), + .m_axis_cq_tuser(axis_cq_tuser), + .m_axis_cq_tvalid(axis_cq_tvalid), + + .s_axis_cc_tdata(axis_cc_tdata), + .s_axis_cc_tkeep(axis_cc_tkeep), + .s_axis_cc_tlast(axis_cc_tlast), + .s_axis_cc_tready(axis_cc_tready), + .s_axis_cc_tuser(axis_cc_tuser), + .s_axis_cc_tvalid(axis_cc_tvalid), + + .pcie_rq_seq_num(), + .pcie_rq_seq_num_vld(), + .pcie_rq_tag(), + .pcie_rq_tag_av(), + .pcie_rq_tag_vld(), + + .pcie_tfc_nph_av(), + .pcie_tfc_npd_av(), + + .pcie_cq_np_req(1'b1), + .pcie_cq_np_req_count(), + + .cfg_phy_link_down(), + .cfg_phy_link_status(), + .cfg_negotiated_width(), + .cfg_current_speed(), + .cfg_max_payload(cfg_max_payload), + .cfg_max_read_req(cfg_max_read_req), + .cfg_function_status(), + .cfg_function_power_state(), + .cfg_vf_status(), + .cfg_vf_power_state(), + .cfg_link_power_state(), + + .cfg_mgmt_addr(cfg_mgmt_addr), + .cfg_mgmt_write(cfg_mgmt_write), + .cfg_mgmt_write_data(cfg_mgmt_write_data), + .cfg_mgmt_byte_enable(cfg_mgmt_byte_enable), + .cfg_mgmt_read(cfg_mgmt_read), + .cfg_mgmt_read_data(cfg_mgmt_read_data), + .cfg_mgmt_read_write_done(cfg_mgmt_read_write_done), + .cfg_mgmt_type1_cfg_reg_access(1'b0), + + .cfg_err_cor_out(), + .cfg_err_nonfatal_out(), + .cfg_err_fatal_out(), + .cfg_local_error(), + .cfg_ltr_enable(), + .cfg_ltssm_state(), + .cfg_rcb_status(), + .cfg_dpa_substate_change(), + .cfg_obff_enable(), + .cfg_pl_status_change(), + .cfg_tph_requester_enable(), + .cfg_tph_st_mode(), + .cfg_vf_tph_requester_enable(), + .cfg_vf_tph_st_mode(), + + .cfg_msg_received(), + .cfg_msg_received_data(), + .cfg_msg_received_type(), + .cfg_msg_transmit(1'b0), + .cfg_msg_transmit_type(3'd0), + .cfg_msg_transmit_data(32'd0), + .cfg_msg_transmit_done(), + + .cfg_fc_ph(), + .cfg_fc_pd(), + .cfg_fc_nph(), + .cfg_fc_npd(), + .cfg_fc_cplh(), + .cfg_fc_cpld(), + .cfg_fc_sel(3'd0), + + .cfg_per_func_status_control(3'd0), + .cfg_per_func_status_data(), + .cfg_per_function_number(4'd0), + .cfg_per_function_output_request(1'b0), + .cfg_per_function_update_done(), + + .cfg_dsn(64'd0), + + .cfg_power_state_change_ack(1'b1), + .cfg_power_state_change_interrupt(), + + .cfg_err_cor_in(status_error_cor), + .cfg_err_uncor_in(status_error_uncor), + .cfg_flr_in_process(), + .cfg_flr_done(4'd0), + .cfg_vf_flr_in_process(), + .cfg_vf_flr_done(8'd0), + + .cfg_link_training_enable(1'b1), + + .cfg_interrupt_int(4'd0), + .cfg_interrupt_pending(4'd0), + .cfg_interrupt_sent(), + .cfg_interrupt_msi_enable(cfg_interrupt_msi_enable), + .cfg_interrupt_msi_vf_enable(cfg_interrupt_msi_vf_enable), + .cfg_interrupt_msi_mmenable(cfg_interrupt_msi_mmenable), + .cfg_interrupt_msi_mask_update(cfg_interrupt_msi_mask_update), + .cfg_interrupt_msi_data(cfg_interrupt_msi_data), + .cfg_interrupt_msi_select(cfg_interrupt_msi_select), + .cfg_interrupt_msi_int(cfg_interrupt_msi_int), + .cfg_interrupt_msi_pending_status(cfg_interrupt_msi_pending_status), + .cfg_interrupt_msi_pending_status_data_enable(cfg_interrupt_msi_pending_status_data_enable), + .cfg_interrupt_msi_pending_status_function_num(cfg_interrupt_msi_pending_status_function_num), + .cfg_interrupt_msi_sent(cfg_interrupt_msi_sent), + .cfg_interrupt_msi_fail(cfg_interrupt_msi_fail), + .cfg_interrupt_msi_attr(cfg_interrupt_msi_attr), + .cfg_interrupt_msi_tph_present(cfg_interrupt_msi_tph_present), + .cfg_interrupt_msi_tph_type(cfg_interrupt_msi_tph_type), + .cfg_interrupt_msi_tph_st_tag(cfg_interrupt_msi_tph_st_tag), + .cfg_interrupt_msi_function_number(cfg_interrupt_msi_function_number), + + .cfg_hot_reset_out(), + + .cfg_config_space_enable(1'b1), + .cfg_req_pm_transition_l23_ready(1'b0), + .cfg_hot_reset_in(1'b0), + + .cfg_ds_port_number(8'd0), + .cfg_ds_bus_number(8'd0), + .cfg_ds_device_number(5'd0), + .cfg_ds_function_number(3'd0), + + .cfg_subsys_vend_id(16'h1234), + + .sys_clk(pcie_sys_clk), + .sys_clk_gt(pcie_sys_clk_gt), + .sys_reset(pcie_reset_n), + .pcie_perstn1_in(1'b0), + .pcie_perstn0_out(), + .pcie_perstn1_out(), + + .int_qpll1lock_out(), + .int_qpll1outrefclk_out(), + .int_qpll1outclk_out(), + .phy_rdy_out() +); + +fpga_core #( + .AXIS_PCIE_DATA_WIDTH(AXIS_PCIE_DATA_WIDTH) +) +core_inst ( + /* + * Clock: 250 MHz + * Synchronous reset + */ + .clk(pcie_user_clk), + .rst(pcie_user_reset), + /* + * GPIO + */ + .sfp_1_led(sfp_1_led), + .sfp_2_led(sfp_2_led), + .sma_led(sma_led), + /* + * PCIe + */ + .m_axis_rq_tdata(axis_rq_tdata), + .m_axis_rq_tkeep(axis_rq_tkeep), + .m_axis_rq_tlast(axis_rq_tlast), + .m_axis_rq_tready(axis_rq_tready), + .m_axis_rq_tuser(axis_rq_tuser), + .m_axis_rq_tvalid(axis_rq_tvalid), + + .s_axis_rc_tdata(axis_rc_tdata), + .s_axis_rc_tkeep(axis_rc_tkeep), + .s_axis_rc_tlast(axis_rc_tlast), + .s_axis_rc_tready(axis_rc_tready), + .s_axis_rc_tuser(axis_rc_tuser), + .s_axis_rc_tvalid(axis_rc_tvalid), + + .s_axis_cq_tdata(axis_cq_tdata), + .s_axis_cq_tkeep(axis_cq_tkeep), + .s_axis_cq_tlast(axis_cq_tlast), + .s_axis_cq_tready(axis_cq_tready), + .s_axis_cq_tuser(axis_cq_tuser), + .s_axis_cq_tvalid(axis_cq_tvalid), + + .m_axis_cc_tdata(axis_cc_tdata), + .m_axis_cc_tkeep(axis_cc_tkeep), + .m_axis_cc_tlast(axis_cc_tlast), + .m_axis_cc_tready(axis_cc_tready), + .m_axis_cc_tuser(axis_cc_tuser), + .m_axis_cc_tvalid(axis_cc_tvalid), + + .cfg_max_payload(cfg_max_payload), + .cfg_max_read_req(cfg_max_read_req), + + .cfg_mgmt_addr(cfg_mgmt_addr), + .cfg_mgmt_write(cfg_mgmt_write), + .cfg_mgmt_write_data(cfg_mgmt_write_data), + .cfg_mgmt_byte_enable(cfg_mgmt_byte_enable), + .cfg_mgmt_read(cfg_mgmt_read), + .cfg_mgmt_read_data(cfg_mgmt_read_data), + .cfg_mgmt_read_write_done(cfg_mgmt_read_write_done), + + .cfg_interrupt_msi_enable(cfg_interrupt_msi_enable), + .cfg_interrupt_msi_vf_enable(cfg_interrupt_msi_vf_enable), + .cfg_interrupt_msi_mmenable(cfg_interrupt_msi_mmenable), + .cfg_interrupt_msi_mask_update(cfg_interrupt_msi_mask_update), + .cfg_interrupt_msi_data(cfg_interrupt_msi_data), + .cfg_interrupt_msi_select(cfg_interrupt_msi_select), + .cfg_interrupt_msi_int(cfg_interrupt_msi_int), + .cfg_interrupt_msi_pending_status(cfg_interrupt_msi_pending_status), + .cfg_interrupt_msi_pending_status_data_enable(cfg_interrupt_msi_pending_status_data_enable), + .cfg_interrupt_msi_pending_status_function_num(cfg_interrupt_msi_pending_status_function_num), + .cfg_interrupt_msi_sent(cfg_interrupt_msi_sent), + .cfg_interrupt_msi_fail(cfg_interrupt_msi_fail), + .cfg_interrupt_msi_attr(cfg_interrupt_msi_attr), + .cfg_interrupt_msi_tph_present(cfg_interrupt_msi_tph_present), + .cfg_interrupt_msi_tph_type(cfg_interrupt_msi_tph_type), + .cfg_interrupt_msi_tph_st_tag(cfg_interrupt_msi_tph_st_tag), + .cfg_interrupt_msi_function_number(cfg_interrupt_msi_function_number), + + .status_error_cor(status_error_cor), + .status_error_uncor(status_error_uncor) +); + +endmodule diff --git a/example/ExaNIC_X10/fpga/rtl/fpga_core.v b/example/ExaNIC_X10/fpga/rtl/fpga_core.v new file mode 100644 index 0000000..1922fe4 --- /dev/null +++ b/example/ExaNIC_X10/fpga/rtl/fpga_core.v @@ -0,0 +1,1089 @@ +/* + +Copyright (c) 2018 Alex Forencich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +// Language: Verilog 2001 + +`timescale 1ns / 1ps + +/* + * FPGA core logic + */ +module fpga_core # +( + parameter AXIS_PCIE_DATA_WIDTH = 256, + parameter AXIS_PCIE_KEEP_WIDTH = (AXIS_PCIE_DATA_WIDTH/32) +) +( + /* + * Clock: 250 MHz + * Synchronous reset + */ + input wire clk, + input wire rst, + + /* + * GPIO + */ + output wire [1:0] sfp_1_led, + output wire [1:0] sfp_2_led, + output wire [1:0] sma_led, + + /* + * PCIe + */ + output wire [AXIS_PCIE_DATA_WIDTH-1:0] m_axis_rq_tdata, + output wire [AXIS_PCIE_KEEP_WIDTH-1:0] m_axis_rq_tkeep, + output wire m_axis_rq_tlast, + input wire m_axis_rq_tready, + output wire [59:0] m_axis_rq_tuser, + output wire m_axis_rq_tvalid, + + input wire [AXIS_PCIE_DATA_WIDTH-1:0] s_axis_rc_tdata, + input wire [AXIS_PCIE_KEEP_WIDTH-1:0] s_axis_rc_tkeep, + input wire s_axis_rc_tlast, + output wire s_axis_rc_tready, + input wire [74:0] s_axis_rc_tuser, + input wire s_axis_rc_tvalid, + + input wire [AXIS_PCIE_DATA_WIDTH-1:0] s_axis_cq_tdata, + input wire [AXIS_PCIE_KEEP_WIDTH-1:0] s_axis_cq_tkeep, + input wire s_axis_cq_tlast, + output wire s_axis_cq_tready, + input wire [84:0] s_axis_cq_tuser, + input wire s_axis_cq_tvalid, + + output wire [AXIS_PCIE_DATA_WIDTH-1:0] m_axis_cc_tdata, + output wire [AXIS_PCIE_KEEP_WIDTH-1:0] m_axis_cc_tkeep, + output wire m_axis_cc_tlast, + input wire m_axis_cc_tready, + output wire [32:0] m_axis_cc_tuser, + output wire m_axis_cc_tvalid, + + input wire [2:0] cfg_max_payload, + input wire [2:0] cfg_max_read_req, + + output wire [18:0] cfg_mgmt_addr, + output wire cfg_mgmt_write, + output wire [31:0] cfg_mgmt_write_data, + output wire [3:0] cfg_mgmt_byte_enable, + output wire cfg_mgmt_read, + input wire [31:0] cfg_mgmt_read_data, + input wire cfg_mgmt_read_write_done, + + input wire [3:0] cfg_interrupt_msi_enable, + input wire [7:0] cfg_interrupt_msi_vf_enable, + input wire [11:0] cfg_interrupt_msi_mmenable, + input wire cfg_interrupt_msi_mask_update, + input wire [31:0] cfg_interrupt_msi_data, + output wire [3:0] cfg_interrupt_msi_select, + output wire [31:0] cfg_interrupt_msi_int, + output wire [31:0] cfg_interrupt_msi_pending_status, + output wire cfg_interrupt_msi_pending_status_data_enable, + output wire [3:0] cfg_interrupt_msi_pending_status_function_num, + input wire cfg_interrupt_msi_sent, + input wire cfg_interrupt_msi_fail, + output wire [2:0] cfg_interrupt_msi_attr, + output wire cfg_interrupt_msi_tph_present, + output wire [1:0] cfg_interrupt_msi_tph_type, + output wire [8:0] cfg_interrupt_msi_tph_st_tag, + output wire [3:0] cfg_interrupt_msi_function_number, + + output wire status_error_cor, + output wire status_error_uncor +); + +parameter PCIE_ADDR_WIDTH = 64; + +parameter AXIL_DATA_WIDTH = 32; +parameter AXIL_STRB_WIDTH = (AXIL_DATA_WIDTH/8); +parameter AXIL_ADDR_WIDTH = 32; + +parameter AXI_DATA_WIDTH = AXIS_PCIE_DATA_WIDTH; +parameter AXI_STRB_WIDTH = (AXI_DATA_WIDTH/8); +parameter AXI_ADDR_WIDTH = 32; +parameter AXI_ID_WIDTH = 8; + +parameter DMA_TAG_WIDTH = 8; + +// Completer mux/demux +wire [AXIS_PCIE_DATA_WIDTH-1:0] axis_cq_tdata_bar_0; +wire [AXIS_PCIE_KEEP_WIDTH-1:0] axis_cq_tkeep_bar_0; +wire axis_cq_tvalid_bar_0; +wire axis_cq_tready_bar_0; +wire axis_cq_tlast_bar_0; +wire [84:0] axis_cq_tuser_bar_0; + +wire [AXIS_PCIE_DATA_WIDTH-1:0] axis_cc_tdata_bar_0; +wire [AXIS_PCIE_KEEP_WIDTH-1:0] axis_cc_tkeep_bar_0; +wire axis_cc_tvalid_bar_0; +wire axis_cc_tready_bar_0; +wire axis_cc_tlast_bar_0; +wire [32:0] axis_cc_tuser_bar_0; + +wire [AXIS_PCIE_DATA_WIDTH-1:0] axis_cq_tdata_bar_1; +wire [AXIS_PCIE_KEEP_WIDTH-1:0] axis_cq_tkeep_bar_1; +wire axis_cq_tvalid_bar_1; +wire axis_cq_tready_bar_1; +wire axis_cq_tlast_bar_1; +wire [84:0] axis_cq_tuser_bar_1; + +wire [AXIS_PCIE_DATA_WIDTH-1:0] axis_cc_tdata_bar_1; +wire [AXIS_PCIE_KEEP_WIDTH-1:0] axis_cc_tkeep_bar_1; +wire axis_cc_tvalid_bar_1; +wire axis_cc_tready_bar_1; +wire axis_cc_tlast_bar_1; +wire [32:0] axis_cc_tuser_bar_1; + +wire [2:0] bar_id; +wire [1:0] select; + +pcie_us_axis_cq_demux #( + .M_COUNT(2), + .AXIS_PCIE_DATA_WIDTH(AXIS_PCIE_DATA_WIDTH), + .AXIS_PCIE_KEEP_WIDTH(AXIS_PCIE_KEEP_WIDTH) +) +cq_demux_inst ( + .clk(clk), + .rst(rst), + + /* + * AXI input (CQ) + */ + .s_axis_cq_tdata(s_axis_cq_tdata), + .s_axis_cq_tkeep(s_axis_cq_tkeep), + .s_axis_cq_tvalid(s_axis_cq_tvalid), + .s_axis_cq_tready(s_axis_cq_tready), + .s_axis_cq_tlast(s_axis_cq_tlast), + .s_axis_cq_tuser(s_axis_cq_tuser), + + /* + * AXI output (CQ) + */ + .m_axis_cq_tdata({axis_cq_tdata_bar_1, axis_cq_tdata_bar_0}), + .m_axis_cq_tkeep({axis_cq_tkeep_bar_1, axis_cq_tkeep_bar_0}), + .m_axis_cq_tvalid({axis_cq_tvalid_bar_1, axis_cq_tvalid_bar_0}), + .m_axis_cq_tready({axis_cq_tready_bar_1, axis_cq_tready_bar_0}), + .m_axis_cq_tlast({axis_cq_tlast_bar_1, axis_cq_tlast_bar_0}), + .m_axis_cq_tuser({axis_cq_tuser_bar_1, axis_cq_tuser_bar_0}), + + /* + * Fields + */ + .req_type(), + .target_function(), + .bar_id(bar_id), + .msg_code(), + .msg_routing(), + + /* + * Control + */ + .enable(1), + .drop(0), + .select(select) +); + +assign select[1] = bar_id == 3'd1; +assign select[0] = bar_id == 3'd0; + +axis_arb_mux #( + .S_COUNT(2), + .DATA_WIDTH(AXIS_PCIE_DATA_WIDTH), + .KEEP_ENABLE(1), + .KEEP_WIDTH(AXIS_PCIE_KEEP_WIDTH), + .ID_ENABLE(0), + .DEST_ENABLE(0), + .USER_ENABLE(1), + .USER_WIDTH(33) +) +cc_mux_inst ( + .clk(clk), + .rst(rst), + + /* + * AXI inputs + */ + .s_axis_tdata({axis_cc_tdata_bar_1, axis_cc_tdata_bar_0}), + .s_axis_tkeep({axis_cc_tkeep_bar_1, axis_cc_tkeep_bar_0}), + .s_axis_tvalid({axis_cc_tvalid_bar_1, axis_cc_tvalid_bar_0}), + .s_axis_tready({axis_cc_tready_bar_1, axis_cc_tready_bar_0}), + .s_axis_tlast({axis_cc_tlast_bar_1, axis_cc_tlast_bar_0}), + .s_axis_tid(0), + .s_axis_tdest(0), + .s_axis_tuser({axis_cc_tuser_bar_1, axis_cc_tuser_bar_0}), + + /* + * AXI output + */ + .m_axis_tdata(m_axis_cc_tdata), + .m_axis_tkeep(m_axis_cc_tkeep), + .m_axis_tvalid(m_axis_cc_tvalid), + .m_axis_tready(m_axis_cc_tready), + .m_axis_tlast(m_axis_cc_tlast), + .m_axis_tid(), + .m_axis_tdest(), + .m_axis_tuser(m_axis_cc_tuser) +); + +wire [AXIL_ADDR_WIDTH-1:0] axil_ctrl_awaddr; +wire [2:0] axil_ctrl_awprot; +wire axil_ctrl_awvalid; +wire axil_ctrl_awready; +wire [AXIL_DATA_WIDTH-1:0] axil_ctrl_wdata; +wire [AXIL_STRB_WIDTH-1:0] axil_ctrl_wstrb; +wire axil_ctrl_wvalid; +wire axil_ctrl_wready; +wire [1:0] axil_ctrl_bresp; +wire axil_ctrl_bvalid; +wire axil_ctrl_bready; +wire [AXIL_ADDR_WIDTH-1:0] axil_ctrl_araddr; +wire [2:0] axil_ctrl_arprot; +wire axil_ctrl_arvalid; +wire axil_ctrl_arready; +wire [AXIL_DATA_WIDTH-1:0] axil_ctrl_rdata; +wire [1:0] axil_ctrl_rresp; +wire axil_ctrl_rvalid; +wire axil_ctrl_rready; + +wire [AXI_ID_WIDTH-1:0] axi_awid; +wire [AXI_ADDR_WIDTH-1:0] axi_awaddr; +wire [7:0] axi_awlen; +wire [2:0] axi_awsize; +wire [1:0] axi_awburst; +wire axi_awlock; +wire [3:0] axi_awcache; +wire [2:0] axi_awprot; +wire axi_awvalid; +wire axi_awready; +wire [AXI_DATA_WIDTH-1:0] axi_wdata; +wire [AXI_STRB_WIDTH-1:0] axi_wstrb; +wire axi_wlast; +wire axi_wvalid; +wire axi_wready; +wire [AXI_ID_WIDTH-1:0] axi_bid; +wire [1:0] axi_bresp; +wire axi_bvalid; +wire axi_bready; +wire [AXI_ID_WIDTH-1:0] axi_arid; +wire [AXI_ADDR_WIDTH-1:0] axi_araddr; +wire [7:0] axi_arlen; +wire [2:0] axi_arsize; +wire [1:0] axi_arburst; +wire axi_arlock; +wire [3:0] axi_arcache; +wire [2:0] axi_arprot; +wire axi_arvalid; +wire axi_arready; +wire [AXI_ID_WIDTH-1:0] axi_rid; +wire [AXI_DATA_WIDTH-1:0] axi_rdata; +wire [1:0] axi_rresp; +wire axi_rlast; +wire axi_rvalid; +wire axi_rready; + +wire [AXI_ID_WIDTH-1:0] axi_dma_awid; +wire [AXI_ADDR_WIDTH-1:0] axi_dma_awaddr; +wire [7:0] axi_dma_awlen; +wire [2:0] axi_dma_awsize; +wire [1:0] axi_dma_awburst; +wire axi_dma_awlock; +wire [3:0] axi_dma_awcache; +wire [2:0] axi_dma_awprot; +wire axi_dma_awvalid; +wire axi_dma_awready; +wire [AXI_DATA_WIDTH-1:0] axi_dma_wdata; +wire [AXI_STRB_WIDTH-1:0] axi_dma_wstrb; +wire axi_dma_wlast; +wire axi_dma_wvalid; +wire axi_dma_wready; +wire [AXI_ID_WIDTH-1:0] axi_dma_bid; +wire [1:0] axi_dma_bresp; +wire axi_dma_bvalid; +wire axi_dma_bready; +wire [AXI_ID_WIDTH-1:0] axi_dma_arid; +wire [AXI_ADDR_WIDTH-1:0] axi_dma_araddr; +wire [7:0] axi_dma_arlen; +wire [2:0] axi_dma_arsize; +wire [1:0] axi_dma_arburst; +wire axi_dma_arlock; +wire [3:0] axi_dma_arcache; +wire [2:0] axi_dma_arprot; +wire axi_dma_arvalid; +wire axi_dma_arready; +wire [AXI_ID_WIDTH-1:0] axi_dma_rid; +wire [AXI_DATA_WIDTH-1:0] axi_dma_rdata; +wire [1:0] axi_dma_rresp; +wire axi_dma_rlast; +wire axi_dma_rvalid; +wire axi_dma_rready; + +// PCIe DMA control +wire [PCIE_ADDR_WIDTH-1:0] pcie_dma_read_desc_pcie_addr; +wire [AXI_ADDR_WIDTH-1:0] pcie_dma_read_desc_axi_addr; +wire [15:0] pcie_dma_read_desc_len; +wire [DMA_TAG_WIDTH-1:0] pcie_dma_read_desc_tag; +wire pcie_dma_read_desc_valid; +wire pcie_dma_read_desc_ready; + +wire [DMA_TAG_WIDTH-1:0] pcie_dma_read_desc_status_tag; +wire pcie_dma_read_desc_status_valid; +wire pcie_dma_read_desc_status_ready; + +wire [PCIE_ADDR_WIDTH-1:0] pcie_dma_write_desc_pcie_addr; +wire [AXI_ADDR_WIDTH-1:0] pcie_dma_write_desc_axi_addr; +wire [15:0] pcie_dma_write_desc_len; +wire [DMA_TAG_WIDTH-1:0] pcie_dma_write_desc_tag; +wire pcie_dma_write_desc_valid; +wire pcie_dma_write_desc_ready; + +wire [DMA_TAG_WIDTH-1:0] pcie_dma_write_desc_status_tag; +wire pcie_dma_write_desc_status_valid; +wire pcie_dma_write_desc_status_ready; + +wire pcie_dma_enable; + +// Error handling +wire [2:0] status_error_uncor_int; +wire [2:0] status_error_cor_int; + +wire [31:0] msi_irq; + +wire ext_tag_enable; + +// control registers +reg axil_ctrl_awready_reg = 1'b0, axil_ctrl_awready_next; +reg axil_ctrl_wready_reg = 1'b0, axil_ctrl_wready_next; +reg [1:0] axil_ctrl_bresp_reg = 2'b00, axil_ctrl_bresp_next; +reg axil_ctrl_bvalid_reg = 1'b0, axil_ctrl_bvalid_next; +reg axil_ctrl_arready_reg = 1'b0, axil_ctrl_arready_next; +reg [AXIL_DATA_WIDTH-1:0] axil_ctrl_rdata_reg = {AXIL_DATA_WIDTH{1'b0}}, axil_ctrl_rdata_next; +reg [1:0] axil_ctrl_rresp_reg = 2'b00, axil_ctrl_rresp_next; +reg axil_ctrl_rvalid_reg = 1'b0, axil_ctrl_rvalid_next; + +reg [PCIE_ADDR_WIDTH-1:0] pcie_dma_read_desc_pcie_addr_reg = 0, pcie_dma_read_desc_pcie_addr_next; +reg [AXI_ADDR_WIDTH-1:0] pcie_dma_read_desc_axi_addr_reg = 0, pcie_dma_read_desc_axi_addr_next; +reg [15:0] pcie_dma_read_desc_len_reg = 0, pcie_dma_read_desc_len_next; +reg [DMA_TAG_WIDTH-1:0] pcie_dma_read_desc_tag_reg = 0, pcie_dma_read_desc_tag_next; +reg pcie_dma_read_desc_valid_reg = 0, pcie_dma_read_desc_valid_next; + +reg pcie_dma_read_desc_status_ready_reg = 0, pcie_dma_read_desc_status_ready_next; + +reg [PCIE_ADDR_WIDTH-1:0] pcie_dma_write_desc_pcie_addr_reg = 0, pcie_dma_write_desc_pcie_addr_next; +reg [AXI_ADDR_WIDTH-1:0] pcie_dma_write_desc_axi_addr_reg = 0, pcie_dma_write_desc_axi_addr_next; +reg [15:0] pcie_dma_write_desc_len_reg = 0, pcie_dma_write_desc_len_next; +reg [DMA_TAG_WIDTH-1:0] pcie_dma_write_desc_tag_reg = 0, pcie_dma_write_desc_tag_next; +reg pcie_dma_write_desc_valid_reg = 0, pcie_dma_write_desc_valid_next; + +reg pcie_dma_write_desc_status_ready_reg = 0, pcie_dma_write_desc_status_ready_next; + +reg pcie_dma_enable_reg = 0, pcie_dma_enable_next; + +reg [31:0] pcie_rq_count_reg = 0; +reg [31:0] pcie_rc_count_reg = 0; +reg [31:0] pcie_cq_count_reg = 0; +reg [31:0] pcie_cc_count_reg = 0; + +assign axil_ctrl_awready = axil_ctrl_awready_reg; +assign axil_ctrl_wready = axil_ctrl_wready_reg; +assign axil_ctrl_bresp = axil_ctrl_bresp_reg; +assign axil_ctrl_bvalid = axil_ctrl_bvalid_reg; +assign axil_ctrl_arready = axil_ctrl_arready_reg; +assign axil_ctrl_rdata = axil_ctrl_rdata_reg; +assign axil_ctrl_rresp = axil_ctrl_rresp_reg; +assign axil_ctrl_rvalid = axil_ctrl_rvalid_reg; + +assign pcie_dma_read_desc_pcie_addr = pcie_dma_read_desc_pcie_addr_reg; +assign pcie_dma_read_desc_axi_addr = pcie_dma_read_desc_axi_addr_reg; +assign pcie_dma_read_desc_len = pcie_dma_read_desc_len_reg; +assign pcie_dma_read_desc_tag = pcie_dma_read_desc_tag_reg; +assign pcie_dma_read_desc_valid = pcie_dma_read_desc_valid_reg; +assign pcie_dma_read_desc_status_ready = pcie_dma_read_desc_status_ready_reg; +assign pcie_dma_write_desc_pcie_addr = pcie_dma_write_desc_pcie_addr_reg; +assign pcie_dma_write_desc_axi_addr = pcie_dma_write_desc_axi_addr_reg; +assign pcie_dma_write_desc_len = pcie_dma_write_desc_len_reg; +assign pcie_dma_write_desc_tag = pcie_dma_write_desc_tag_reg; +assign pcie_dma_write_desc_valid = pcie_dma_write_desc_valid_reg; +assign pcie_dma_write_desc_status_ready = pcie_dma_write_desc_status_ready_reg; +assign pcie_dma_enable = pcie_dma_enable_reg; + +assign msi_irq[0] = pcie_dma_read_desc_status_valid || pcie_dma_write_desc_status_valid; +assign msi_irq[31:1] = 0; + +always @* begin + axil_ctrl_awready_next = 1'b0; + axil_ctrl_wready_next = 1'b0; + axil_ctrl_bresp_next = 2'b00; + axil_ctrl_bvalid_next = axil_ctrl_bvalid_reg && !axil_ctrl_bready; + axil_ctrl_arready_next = 1'b0; + axil_ctrl_rdata_next = {AXIL_DATA_WIDTH{1'b0}}; + axil_ctrl_rresp_next = 2'b00; + axil_ctrl_rvalid_next = axil_ctrl_rvalid_reg && !axil_ctrl_rready; + + pcie_dma_read_desc_pcie_addr_next = pcie_dma_read_desc_pcie_addr_reg; + pcie_dma_read_desc_axi_addr_next = pcie_dma_read_desc_axi_addr_reg; + pcie_dma_read_desc_len_next = pcie_dma_read_desc_len_reg; + pcie_dma_read_desc_tag_next = pcie_dma_read_desc_tag_reg; + pcie_dma_read_desc_valid_next = pcie_dma_read_desc_valid_reg && !pcie_dma_read_desc_ready; + pcie_dma_read_desc_status_ready_next = 1'b0; + + pcie_dma_write_desc_pcie_addr_next = pcie_dma_write_desc_pcie_addr_reg; + pcie_dma_write_desc_axi_addr_next = pcie_dma_write_desc_axi_addr_reg; + pcie_dma_write_desc_len_next = pcie_dma_write_desc_len_reg; + pcie_dma_write_desc_tag_next = pcie_dma_write_desc_tag_reg; + pcie_dma_write_desc_valid_next = pcie_dma_write_desc_valid_reg && !pcie_dma_read_desc_ready; + pcie_dma_write_desc_status_ready_next = 1'b0; + + pcie_dma_enable_next = pcie_dma_enable_reg; + + if (axil_ctrl_awvalid && axil_ctrl_wvalid && !axil_ctrl_bvalid) begin + // write operation + axil_ctrl_awready_next = 1'b1; + axil_ctrl_wready_next = 1'b1; + axil_ctrl_bresp_next = 2'b00; + axil_ctrl_bvalid_next = 1'b1; + + case ({axil_ctrl_awaddr[15:2], 2'b00}) + 16'h0000: pcie_dma_enable_next = axil_ctrl_wdata; + 16'h0100: pcie_dma_read_desc_pcie_addr_next[31:0] = axil_ctrl_wdata; + 16'h0104: pcie_dma_read_desc_pcie_addr_next[63:32] = axil_ctrl_wdata; + 16'h0108: pcie_dma_read_desc_axi_addr_next[31:0] = axil_ctrl_wdata; + //16'h010C: pcie_dma_read_desc_axi_addr_next[63:32] = axil_ctrl_wdata; + 16'h0110: pcie_dma_read_desc_len_next = axil_ctrl_wdata; + 16'h0114: begin + pcie_dma_read_desc_tag_next = axil_ctrl_wdata; + pcie_dma_read_desc_valid_next = 1'b1; + end + 16'h0200: pcie_dma_write_desc_pcie_addr_next[31:0] = axil_ctrl_wdata; + 16'h0204: pcie_dma_write_desc_pcie_addr_next[63:32] = axil_ctrl_wdata; + 16'h0208: pcie_dma_write_desc_axi_addr_next[31:0] = axil_ctrl_wdata; + //16'h020C: pcie_dma_write_desc_axi_addr_next[63:32] = axil_ctrl_wdata; + 16'h0210: pcie_dma_write_desc_len_next = axil_ctrl_wdata; + 16'h0214: begin + pcie_dma_write_desc_tag_next = axil_ctrl_wdata; + pcie_dma_write_desc_valid_next = 1'b1; + end + endcase + end + + if (axil_ctrl_arvalid && !axil_ctrl_rvalid) begin + // read operation + axil_ctrl_arready_next = 1'b1; + axil_ctrl_rresp_next = 2'b00; + axil_ctrl_rvalid_next = 1'b1; + + case ({axil_ctrl_araddr[15:2], 2'b00}) + 16'h0000: axil_ctrl_rdata_next = pcie_dma_enable_reg; + 16'h0118: begin + axil_ctrl_rdata_next = pcie_dma_read_desc_status_tag | (pcie_dma_read_desc_status_valid ? 32'h80000000 : 32'd0); + pcie_dma_read_desc_status_ready_next = pcie_dma_read_desc_status_valid; + end + 16'h0218: begin + axil_ctrl_rdata_next = pcie_dma_write_desc_status_tag | (pcie_dma_write_desc_status_valid ? 32'h80000000 : 32'd0); + pcie_dma_write_desc_status_ready_next = pcie_dma_write_desc_status_valid; + end + 16'h0400: axil_ctrl_rdata_next = pcie_rq_count_reg; + 16'h0404: axil_ctrl_rdata_next = pcie_rc_count_reg; + 16'h0408: axil_ctrl_rdata_next = pcie_cq_count_reg; + 16'h040C: axil_ctrl_rdata_next = pcie_cc_count_reg; + endcase + end +end + +always @(posedge clk) begin + if (rst) begin + axil_ctrl_awready_reg <= 1'b0; + axil_ctrl_wready_reg <= 1'b0; + axil_ctrl_bvalid_reg <= 1'b0; + axil_ctrl_arready_reg <= 1'b0; + axil_ctrl_rvalid_reg <= 1'b0; + + pcie_dma_read_desc_valid_reg <= 1'b0; + pcie_dma_read_desc_status_ready_reg <= 1'b0; + pcie_dma_write_desc_valid_reg <= 1'b0; + pcie_dma_write_desc_status_ready_reg <= 1'b0; + pcie_dma_enable_reg <= 1'b0; + + pcie_rq_count_reg <= 0; + pcie_rc_count_reg <= 0; + pcie_cq_count_reg <= 0; + pcie_cc_count_reg <= 0; + end else begin + axil_ctrl_awready_reg <= axil_ctrl_awready_next; + axil_ctrl_wready_reg <= axil_ctrl_wready_next; + axil_ctrl_bvalid_reg <= axil_ctrl_bvalid_next; + axil_ctrl_arready_reg <= axil_ctrl_arready_next; + axil_ctrl_rvalid_reg <= axil_ctrl_rvalid_next; + + pcie_dma_read_desc_valid_reg <= pcie_dma_read_desc_valid_next; + pcie_dma_read_desc_status_ready_reg <= pcie_dma_read_desc_status_ready_next; + pcie_dma_write_desc_valid_reg <= pcie_dma_write_desc_valid_next; + pcie_dma_write_desc_status_ready_reg <= pcie_dma_write_desc_status_ready_next; + pcie_dma_enable_reg <= pcie_dma_enable_next; + + if (m_axis_rq_tready && m_axis_rq_tvalid && m_axis_rq_tlast) begin + pcie_rq_count_reg <= pcie_rq_count_reg + 1; + end + + if (s_axis_rc_tready && s_axis_rc_tvalid && s_axis_rc_tlast) begin + pcie_rc_count_reg <= pcie_rc_count_reg + 1; + end + + if (s_axis_cq_tready && s_axis_cq_tvalid && s_axis_cq_tlast) begin + pcie_cq_count_reg <= pcie_cq_count_reg + 1; + end + + if (m_axis_cc_tready && m_axis_cc_tvalid && m_axis_cc_tlast) begin + pcie_cc_count_reg <= pcie_cc_count_reg + 1; + end + end + + axil_ctrl_bresp_reg <= axil_ctrl_bresp_next; + axil_ctrl_rdata_reg <= axil_ctrl_rdata_next; + axil_ctrl_rresp_reg <= axil_ctrl_rresp_next; + + pcie_dma_read_desc_pcie_addr_reg <= pcie_dma_read_desc_pcie_addr_next; + pcie_dma_read_desc_axi_addr_reg <= pcie_dma_read_desc_axi_addr_next; + pcie_dma_read_desc_len_reg <= pcie_dma_read_desc_len_next; + pcie_dma_read_desc_tag_reg <= pcie_dma_read_desc_tag_next; + pcie_dma_write_desc_pcie_addr_reg <= pcie_dma_write_desc_pcie_addr_next; + pcie_dma_write_desc_axi_addr_reg <= pcie_dma_write_desc_axi_addr_next; + pcie_dma_write_desc_len_reg <= pcie_dma_write_desc_len_next; + pcie_dma_write_desc_tag_reg <= pcie_dma_write_desc_tag_next; +end + +assign sfp_1_led = 2'b00; +assign sfp_2_led = 2'b00; +assign sma_led = 2'b00; + +pcie_us_cfg #( + .PF_COUNT(1), + .VF_COUNT(0), + .VF_OFFSET(64), + .PCIE_CAP_OFFSET(12'h0C0) +) +pcie_us_cfg_inst ( + .clk(clk), + .rst(rst), + + /* + * Configuration outputs + */ + .ext_tag_enable(ext_tag_enable), + .max_read_request_size(), + .max_payload_size(), + + /* + * Interface to Ultrascale PCIe IP core + */ + .cfg_mgmt_addr(cfg_mgmt_addr[9:0]), + .cfg_mgmt_function_number(cfg_mgmt_addr[17:10]), + .cfg_mgmt_write(cfg_mgmt_write), + .cfg_mgmt_write_data(cfg_mgmt_write_data), + .cfg_mgmt_byte_enable(cfg_mgmt_byte_enable), + .cfg_mgmt_read(cfg_mgmt_read), + .cfg_mgmt_read_data(cfg_mgmt_read_data), + .cfg_mgmt_read_write_done(cfg_mgmt_read_write_done) +); + +assign cfg_mgmt_addr[18] = 1'b0; + +pcie_us_axil_master #( + .AXIS_PCIE_DATA_WIDTH(AXIS_PCIE_DATA_WIDTH), + .AXI_DATA_WIDTH(AXIL_DATA_WIDTH), + .AXI_ADDR_WIDTH(AXIL_ADDR_WIDTH), + .ENABLE_PARITY(0) +) +pcie_us_axil_master_inst ( + .clk(clk), + .rst(rst), + + /* + * AXI input (CQ) + */ + .s_axis_cq_tdata(axis_cq_tdata_bar_0), + .s_axis_cq_tkeep(axis_cq_tkeep_bar_0), + .s_axis_cq_tvalid(axis_cq_tvalid_bar_0), + .s_axis_cq_tready(axis_cq_tready_bar_0), + .s_axis_cq_tlast(axis_cq_tlast_bar_0), + .s_axis_cq_tuser(axis_cq_tuser_bar_0), + + /* + * AXI input (CC) + */ + .m_axis_cc_tdata(axis_cc_tdata_bar_0), + .m_axis_cc_tkeep(axis_cc_tkeep_bar_0), + .m_axis_cc_tvalid(axis_cc_tvalid_bar_0), + .m_axis_cc_tready(axis_cc_tready_bar_0), + .m_axis_cc_tlast(axis_cc_tlast_bar_0), + .m_axis_cc_tuser(axis_cc_tuser_bar_0), + + /* + * AXI Lite Master output + */ + .m_axil_awaddr(axil_ctrl_awaddr), + .m_axil_awprot(axil_ctrl_awprot), + .m_axil_awvalid(axil_ctrl_awvalid), + .m_axil_awready(axil_ctrl_awready), + .m_axil_wdata(axil_ctrl_wdata), + .m_axil_wstrb(axil_ctrl_wstrb), + .m_axil_wvalid(axil_ctrl_wvalid), + .m_axil_wready(axil_ctrl_wready), + .m_axil_bresp(axil_ctrl_bresp), + .m_axil_bvalid(axil_ctrl_bvalid), + .m_axil_bready(axil_ctrl_bready), + .m_axil_araddr(axil_ctrl_araddr), + .m_axil_arprot(axil_ctrl_arprot), + .m_axil_arvalid(axil_ctrl_arvalid), + .m_axil_arready(axil_ctrl_arready), + .m_axil_rdata(axil_ctrl_rdata), + .m_axil_rresp(axil_ctrl_rresp), + .m_axil_rvalid(axil_ctrl_rvalid), + .m_axil_rready(axil_ctrl_rready), + + /* + * Configuration + */ + .completer_id({8'd0, 5'd0, 3'd0}), + .completer_id_enable(1'b0), + + /* + * Status + */ + .status_error_cor(status_error_cor_int[0]), + .status_error_uncor(status_error_uncor_int[0]) +); + +pcie_us_axi_master #( + .AXIS_PCIE_DATA_WIDTH(AXIS_PCIE_DATA_WIDTH), + .AXIS_PCIE_KEEP_WIDTH(AXIS_PCIE_KEEP_WIDTH), + .AXI_DATA_WIDTH(AXI_DATA_WIDTH), + .AXI_ADDR_WIDTH(AXI_ADDR_WIDTH), + .AXI_STRB_WIDTH(AXI_STRB_WIDTH), + .AXI_ID_WIDTH(AXI_ID_WIDTH) +) +pcie_us_axi_master_inst ( + .clk(clk), + .rst(rst), + + /* + * AXI input (CQ) + */ + .s_axis_cq_tdata(axis_cq_tdata_bar_1), + .s_axis_cq_tkeep(axis_cq_tkeep_bar_1), + .s_axis_cq_tvalid(axis_cq_tvalid_bar_1), + .s_axis_cq_tready(axis_cq_tready_bar_1), + .s_axis_cq_tlast(axis_cq_tlast_bar_1), + .s_axis_cq_tuser(axis_cq_tuser_bar_1), + + /* + * AXI output (CC) + */ + .m_axis_cc_tdata(axis_cc_tdata_bar_1), + .m_axis_cc_tkeep(axis_cc_tkeep_bar_1), + .m_axis_cc_tvalid(axis_cc_tvalid_bar_1), + .m_axis_cc_tready(axis_cc_tready_bar_1), + .m_axis_cc_tlast(axis_cc_tlast_bar_1), + .m_axis_cc_tuser(axis_cc_tuser_bar_1), + + /* + * AXI Master output + */ + .m_axi_awid(axi_awid), + .m_axi_awaddr(axi_awaddr), + .m_axi_awlen(axi_awlen), + .m_axi_awsize(axi_awsize), + .m_axi_awburst(axi_awburst), + .m_axi_awlock(axi_awlock), + .m_axi_awcache(axi_awcache), + .m_axi_awprot(axi_awprot), + .m_axi_awvalid(axi_awvalid), + .m_axi_awready(axi_awready), + .m_axi_wdata(axi_wdata), + .m_axi_wstrb(axi_wstrb), + .m_axi_wlast(axi_wlast), + .m_axi_wvalid(axi_wvalid), + .m_axi_wready(axi_wready), + .m_axi_bid(axi_bid), + .m_axi_bresp(axi_bresp), + .m_axi_bvalid(axi_bvalid), + .m_axi_bready(axi_bready), + .m_axi_arid(axi_arid), + .m_axi_araddr(axi_araddr), + .m_axi_arlen(axi_arlen), + .m_axi_arsize(axi_arsize), + .m_axi_arburst(axi_arburst), + .m_axi_arlock(axi_arlock), + .m_axi_arcache(axi_arcache), + .m_axi_arprot(axi_arprot), + .m_axi_arvalid(axi_arvalid), + .m_axi_arready(axi_arready), + .m_axi_rid(axi_rid), + .m_axi_rdata(axi_rdata), + .m_axi_rresp(axi_rresp), + .m_axi_rlast(axi_rlast), + .m_axi_rvalid(axi_rvalid), + .m_axi_rready(axi_rready), + + /* + * Configuration + */ + .completer_id({8'd0, 5'd0, 3'd1}), + .completer_id_enable(1'b0), + .max_payload_size(cfg_max_payload), + + /* + * Status + */ + .status_error_cor(status_error_cor_int[1]), + .status_error_uncor(status_error_uncor_int[1]) +); + +axi_ram #( + .DATA_WIDTH(AXI_DATA_WIDTH), + .ADDR_WIDTH(16), + .ID_WIDTH(AXI_ID_WIDTH), + .PIPELINE_OUTPUT(1) +) +axi_ram_inst ( + .clk(clk), + .rst(rst), + .s_axi_awid(axi_awid), + .s_axi_awaddr(axi_awaddr), + .s_axi_awlen(axi_awlen), + .s_axi_awsize(axi_awsize), + .s_axi_awburst(axi_awburst), + .s_axi_awlock(axi_awlock), + .s_axi_awcache(axi_awcache), + .s_axi_awprot(axi_awprot), + .s_axi_awvalid(axi_awvalid), + .s_axi_awready(axi_awready), + .s_axi_wdata(axi_wdata), + .s_axi_wstrb(axi_wstrb), + .s_axi_wlast(axi_wlast), + .s_axi_wvalid(axi_wvalid), + .s_axi_wready(axi_wready), + .s_axi_bid(axi_bid), + .s_axi_bresp(axi_bresp), + .s_axi_bvalid(axi_bvalid), + .s_axi_bready(axi_bready), + .s_axi_arid(axi_arid), + .s_axi_araddr(axi_araddr), + .s_axi_arlen(axi_arlen), + .s_axi_arsize(axi_arsize), + .s_axi_arburst(axi_arburst), + .s_axi_arlock(axi_arlock), + .s_axi_arcache(axi_arcache), + .s_axi_arprot(axi_arprot), + .s_axi_arvalid(axi_arvalid), + .s_axi_arready(axi_arready), + .s_axi_rid(axi_rid), + .s_axi_rdata(axi_rdata), + .s_axi_rresp(axi_rresp), + .s_axi_rlast(axi_rlast), + .s_axi_rvalid(axi_rvalid), + .s_axi_rready(axi_rready) +); + +wire [AXIS_PCIE_DATA_WIDTH-1:0] axis_rc_tdata_r; +wire [AXIS_PCIE_KEEP_WIDTH-1:0] axis_rc_tkeep_r; +wire axis_rc_tlast_r; +wire axis_rc_tready_r; +wire [74:0] axis_rc_tuser_r; +wire axis_rc_tvalid_r; + +axis_register #( + .DATA_WIDTH(AXIS_PCIE_DATA_WIDTH), + .KEEP_ENABLE(1), + .KEEP_WIDTH(AXIS_PCIE_KEEP_WIDTH), + .LAST_ENABLE(1), + .ID_ENABLE(0), + .DEST_ENABLE(0), + .USER_ENABLE(1), + .USER_WIDTH(75) +) +rq_reg ( + .clk(clk), + .rst(rst), + + /* + * AXI input + */ + .s_axis_tdata(s_axis_rc_tdata), + .s_axis_tkeep(s_axis_rc_tkeep), + .s_axis_tvalid(s_axis_rc_tvalid), + .s_axis_tready(s_axis_rc_tready), + .s_axis_tlast(s_axis_rc_tlast), + .s_axis_tid(0), + .s_axis_tdest(0), + .s_axis_tuser(s_axis_rc_tuser), + + /* + * AXI output + */ + .m_axis_tdata(axis_rc_tdata_r), + .m_axis_tkeep(axis_rc_tkeep_r), + .m_axis_tvalid(axis_rc_tvalid_r), + .m_axis_tready(axis_rc_tready_r), + .m_axis_tlast(axis_rc_tlast_r), + .m_axis_tid(), + .m_axis_tdest(), + .m_axis_tuser(axis_rc_tuser_r) +); + +pcie_us_axi_dma #( + .AXIS_PCIE_DATA_WIDTH(AXIS_PCIE_DATA_WIDTH), + .AXIS_PCIE_KEEP_WIDTH(AXIS_PCIE_KEEP_WIDTH), + .AXI_DATA_WIDTH(AXI_DATA_WIDTH), + .AXI_ADDR_WIDTH(AXI_ADDR_WIDTH), + .AXI_STRB_WIDTH(AXI_STRB_WIDTH), + .AXI_ID_WIDTH(AXI_ID_WIDTH), + .AXI_MAX_BURST_LEN(256), + .PCIE_ADDR_WIDTH(PCIE_ADDR_WIDTH), + .PCIE_CLIENT_TAG(1), + //.PCIE_TAG_WIDTH(8), + .PCIE_TAG_COUNT(256), + .PCIE_EXT_TAG_ENABLE(1), + .LEN_WIDTH(16), + .TAG_WIDTH(DMA_TAG_WIDTH) +) +pcie_us_axi_dma_inst ( + .clk(clk), + .rst(rst), + + /* + * AXI input (RC) + */ + .s_axis_rc_tdata(axis_rc_tdata_r), + .s_axis_rc_tkeep(axis_rc_tkeep_r), + .s_axis_rc_tvalid(axis_rc_tvalid_r), + .s_axis_rc_tready(axis_rc_tready_r), + .s_axis_rc_tlast(axis_rc_tlast_r), + .s_axis_rc_tuser(axis_rc_tuser_r), + + /* + * AXI output (RQ) + */ + .m_axis_rq_tdata(m_axis_rq_tdata), + .m_axis_rq_tkeep(m_axis_rq_tkeep), + .m_axis_rq_tvalid(m_axis_rq_tvalid), + .m_axis_rq_tready(m_axis_rq_tready), + .m_axis_rq_tlast(m_axis_rq_tlast), + .m_axis_rq_tuser(m_axis_rq_tuser), + + /* + * Tag input + */ + .s_axis_pcie_rq_tag(0), + .s_axis_pcie_rq_tag_valid(0), + + /* + * AXI read descriptor input + */ + .s_axis_read_desc_pcie_addr(pcie_dma_read_desc_pcie_addr), + .s_axis_read_desc_axi_addr(pcie_dma_read_desc_axi_addr), + .s_axis_read_desc_len(pcie_dma_read_desc_len), + .s_axis_read_desc_tag(pcie_dma_read_desc_tag), + .s_axis_read_desc_valid(pcie_dma_read_desc_valid), + .s_axis_read_desc_ready(pcie_dma_read_desc_ready), + + /* + * AXI read descriptor status output + */ + .m_axis_read_desc_status_tag(pcie_dma_read_desc_status_tag), + .m_axis_read_desc_status_valid(pcie_dma_read_desc_status_valid), + + /* + * AXI write descriptor input + */ + .s_axis_write_desc_pcie_addr(pcie_dma_write_desc_pcie_addr), + .s_axis_write_desc_axi_addr(pcie_dma_write_desc_axi_addr), + .s_axis_write_desc_len(pcie_dma_write_desc_len), + .s_axis_write_desc_tag(pcie_dma_write_desc_tag), + .s_axis_write_desc_valid(pcie_dma_write_desc_valid), + .s_axis_write_desc_ready(pcie_dma_write_desc_ready), + + /* + * AXI write descriptor status output + */ + .m_axis_write_desc_status_tag(pcie_dma_write_desc_status_tag), + .m_axis_write_desc_status_valid(pcie_dma_write_desc_status_valid), + + /* + * AXI Master output + */ + .m_axi_awid(axi_dma_awid), + .m_axi_awaddr(axi_dma_awaddr), + .m_axi_awlen(axi_dma_awlen), + .m_axi_awsize(axi_dma_awsize), + .m_axi_awburst(axi_dma_awburst), + .m_axi_awlock(axi_dma_awlock), + .m_axi_awcache(axi_dma_awcache), + .m_axi_awprot(axi_dma_awprot), + .m_axi_awvalid(axi_dma_awvalid), + .m_axi_awready(axi_dma_awready), + .m_axi_wdata(axi_dma_wdata), + .m_axi_wstrb(axi_dma_wstrb), + .m_axi_wlast(axi_dma_wlast), + .m_axi_wvalid(axi_dma_wvalid), + .m_axi_wready(axi_dma_wready), + .m_axi_bid(axi_dma_bid), + .m_axi_bresp(axi_dma_bresp), + .m_axi_bvalid(axi_dma_bvalid), + .m_axi_bready(axi_dma_bready), + .m_axi_arid(axi_dma_arid), + .m_axi_araddr(axi_dma_araddr), + .m_axi_arlen(axi_dma_arlen), + .m_axi_arsize(axi_dma_arsize), + .m_axi_arburst(axi_dma_arburst), + .m_axi_arlock(axi_dma_arlock), + .m_axi_arcache(axi_dma_arcache), + .m_axi_arprot(axi_dma_arprot), + .m_axi_arvalid(axi_dma_arvalid), + .m_axi_arready(axi_dma_arready), + .m_axi_rid(axi_dma_rid), + .m_axi_rdata(axi_dma_rdata), + .m_axi_rresp(axi_dma_rresp), + .m_axi_rlast(axi_dma_rlast), + .m_axi_rvalid(axi_dma_rvalid), + .m_axi_rready(axi_dma_rready), + + /* + * Configuration + */ + .read_enable(pcie_dma_enable), + .write_enable(pcie_dma_enable), + .ext_tag_enable(ext_tag_enable), + .requester_id({8'd0, 5'd0, 3'd0}), + .requester_id_enable(1'b0), + .max_read_request_size(cfg_max_read_req), + .max_payload_size(cfg_max_payload), + + /* + * Status + */ + .status_error_cor(status_error_cor_int[2]), + .status_error_uncor(status_error_uncor_int[2]) +); + +axi_ram #( + .DATA_WIDTH(AXI_DATA_WIDTH), + .ADDR_WIDTH(16), + .ID_WIDTH(AXI_ID_WIDTH), + .PIPELINE_OUTPUT(1) +) +axi_dma_ram_inst ( + .clk(clk), + .rst(rst), + .s_axi_awid(axi_dma_awid), + .s_axi_awaddr(axi_dma_awaddr), + .s_axi_awlen(axi_dma_awlen), + .s_axi_awsize(axi_dma_awsize), + .s_axi_awburst(axi_dma_awburst), + .s_axi_awlock(axi_dma_awlock), + .s_axi_awcache(axi_dma_awcache), + .s_axi_awprot(axi_dma_awprot), + .s_axi_awvalid(axi_dma_awvalid), + .s_axi_awready(axi_dma_awready), + .s_axi_wdata(axi_dma_wdata), + .s_axi_wstrb(axi_dma_wstrb), + .s_axi_wlast(axi_dma_wlast), + .s_axi_wvalid(axi_dma_wvalid), + .s_axi_wready(axi_dma_wready), + .s_axi_bid(axi_dma_bid), + .s_axi_bresp(axi_dma_bresp), + .s_axi_bvalid(axi_dma_bvalid), + .s_axi_bready(axi_dma_bready), + .s_axi_arid(axi_dma_arid), + .s_axi_araddr(axi_dma_araddr), + .s_axi_arlen(axi_dma_arlen), + .s_axi_arsize(axi_dma_arsize), + .s_axi_arburst(axi_dma_arburst), + .s_axi_arlock(axi_dma_arlock), + .s_axi_arcache(axi_dma_arcache), + .s_axi_arprot(axi_dma_arprot), + .s_axi_arvalid(axi_dma_arvalid), + .s_axi_arready(axi_dma_arready), + .s_axi_rid(axi_dma_rid), + .s_axi_rdata(axi_dma_rdata), + .s_axi_rresp(axi_dma_rresp), + .s_axi_rlast(axi_dma_rlast), + .s_axi_rvalid(axi_dma_rvalid), + .s_axi_rready(axi_dma_rready) +); + +pulse_merge #( + .INPUT_WIDTH(3), + .COUNT_WIDTH(4) +) +status_error_cor_pm_inst ( + .clk(clk), + .rst(rst), + + .pulse_in(status_error_cor_int), + .count_out(), + .pulse_out(status_error_cor) +); + +pulse_merge #( + .INPUT_WIDTH(3), + .COUNT_WIDTH(4) +) +status_error_uncor_pm_inst ( + .clk(clk), + .rst(rst), + + .pulse_in(status_error_uncor_int), + .count_out(), + .pulse_out(status_error_uncor) +); + +pcie_us_msi #( + .MSI_COUNT(32) +) +pcie_us_msi_inst ( + .clk(clk), + .rst(rst), + + .msi_irq(msi_irq), + + .cfg_interrupt_msi_enable(cfg_interrupt_msi_enable), + .cfg_interrupt_msi_vf_enable(cfg_interrupt_msi_vf_enable), + .cfg_interrupt_msi_mmenable(cfg_interrupt_msi_mmenable), + .cfg_interrupt_msi_mask_update(cfg_interrupt_msi_mask_update), + .cfg_interrupt_msi_data(cfg_interrupt_msi_data), + .cfg_interrupt_msi_select(cfg_interrupt_msi_select), + .cfg_interrupt_msi_int(cfg_interrupt_msi_int), + .cfg_interrupt_msi_pending_status(cfg_interrupt_msi_pending_status), + .cfg_interrupt_msi_pending_status_data_enable(cfg_interrupt_msi_pending_status_data_enable), + .cfg_interrupt_msi_pending_status_function_num(cfg_interrupt_msi_pending_status_function_num), + .cfg_interrupt_msi_sent(cfg_interrupt_msi_sent), + .cfg_interrupt_msi_fail(cfg_interrupt_msi_fail), + .cfg_interrupt_msi_attr(cfg_interrupt_msi_attr), + .cfg_interrupt_msi_tph_present(cfg_interrupt_msi_tph_present), + .cfg_interrupt_msi_tph_type(cfg_interrupt_msi_tph_type), + .cfg_interrupt_msi_tph_st_tag(cfg_interrupt_msi_tph_st_tag), + .cfg_interrupt_msi_function_number(cfg_interrupt_msi_function_number) +); + +endmodule diff --git a/example/ExaNIC_X10/fpga/rtl/sync_reset.v b/example/ExaNIC_X10/fpga/rtl/sync_reset.v new file mode 100644 index 0000000..acbcf1c --- /dev/null +++ b/example/ExaNIC_X10/fpga/rtl/sync_reset.v @@ -0,0 +1,52 @@ +/* + +Copyright (c) 2014-2018 Alex Forencich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +// Language: Verilog-2001 + +`timescale 1 ns / 1 ps + +/* + * Synchronizes an active-high asynchronous reset signal to a given clock by + * using a pipeline of N registers. + */ +module sync_reset #( + parameter N=2 // depth of synchronizer +)( + input wire clk, + input wire rst, + output wire sync_reset_out +); + +reg [N-1:0] sync_reg = {N{1'b1}}; + +assign sync_reset_out = sync_reg[N-1]; + +always @(posedge clk or posedge rst) begin + if (rst) + sync_reg <= {N{1'b1}}; + else + sync_reg <= {sync_reg[N-2:0], 1'b0}; +end + +endmodule diff --git a/example/ExaNIC_X10/fpga/rtl/sync_signal.v b/example/ExaNIC_X10/fpga/rtl/sync_signal.v new file mode 100644 index 0000000..b2a8ce3 --- /dev/null +++ b/example/ExaNIC_X10/fpga/rtl/sync_signal.v @@ -0,0 +1,58 @@ +/* + +Copyright (c) 2014-2018 Alex Forencich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +// Language: Verilog-2001 + +`timescale 1 ns / 1 ps + +/* + * Synchronizes an asyncronous signal to a given clock by using a pipeline of + * two registers. + */ +module sync_signal #( + parameter WIDTH=1, // width of the input and output signals + parameter N=2 // depth of synchronizer +)( + input wire clk, + input wire [WIDTH-1:0] in, + output wire [WIDTH-1:0] out +); + +reg [WIDTH-1:0] sync_reg[N-1:0]; + +/* + * The synchronized output is the last register in the pipeline. + */ +assign out = sync_reg[N-1]; + +integer k; + +always @(posedge clk) begin + sync_reg[0] <= in; + for (k = 1; k < N; k = k + 1) begin + sync_reg[k] <= sync_reg[k-1]; + end +end + +endmodule diff --git a/example/ExaNIC_X10/fpga/tb/axis_ep.py b/example/ExaNIC_X10/fpga/tb/axis_ep.py new file mode 120000 index 0000000..101b21c --- /dev/null +++ b/example/ExaNIC_X10/fpga/tb/axis_ep.py @@ -0,0 +1 @@ +../lib/pcie/tb/axis_ep.py \ No newline at end of file diff --git a/example/ExaNIC_X10/fpga/tb/pcie.py b/example/ExaNIC_X10/fpga/tb/pcie.py new file mode 120000 index 0000000..abea2f9 --- /dev/null +++ b/example/ExaNIC_X10/fpga/tb/pcie.py @@ -0,0 +1 @@ +../lib/pcie/tb/pcie.py \ No newline at end of file diff --git a/example/ExaNIC_X10/fpga/tb/pcie_us.py b/example/ExaNIC_X10/fpga/tb/pcie_us.py new file mode 120000 index 0000000..ef028ec --- /dev/null +++ b/example/ExaNIC_X10/fpga/tb/pcie_us.py @@ -0,0 +1 @@ +../lib/pcie/tb/pcie_us.py \ No newline at end of file diff --git a/example/ExaNIC_X10/fpga/tb/test_fpga_core.py b/example/ExaNIC_X10/fpga/tb/test_fpga_core.py new file mode 100755 index 0000000..85e6b7d --- /dev/null +++ b/example/ExaNIC_X10/fpga/tb/test_fpga_core.py @@ -0,0 +1,507 @@ +#!/usr/bin/env python +""" + +Copyright (c) 2018 Alex Forencich + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +""" + +from myhdl import * +import os +import struct + +import pcie +import pcie_us + +module = 'fpga_core' +testbench = 'test_%s' % module + +srcs = [] + +srcs.append("../rtl/%s.v" % module) +srcs.append("../rtl/axi_ram.v") +srcs.append("../rtl/axis_register.v") +srcs.append("../lib/pcie/rtl/axis_arb_mux.v") +srcs.append("../lib/pcie/rtl/pcie_us_axil_master.v") +srcs.append("../lib/pcie/rtl/pcie_us_axi_dma.v") +srcs.append("../lib/pcie/rtl/pcie_us_axi_dma_rd.v") +srcs.append("../lib/pcie/rtl/pcie_us_axi_dma_wr.v") +srcs.append("../lib/pcie/rtl/pcie_tag_manager.v") +srcs.append("../lib/pcie/rtl/pcie_us_axi_master.v") +srcs.append("../lib/pcie/rtl/pcie_us_axi_master_rd.v") +srcs.append("../lib/pcie/rtl/pcie_us_axi_master_wr.v") +srcs.append("../lib/pcie/rtl/pcie_us_axis_cq_demux.v") +srcs.append("../lib/pcie/rtl/pcie_us_cfg.v") +srcs.append("../lib/pcie/rtl/pcie_us_msi.v") +srcs.append("../lib/pcie/rtl/arbiter.v") +srcs.append("../lib/pcie/rtl/priority_encoder.v") +srcs.append("../lib/pcie/rtl/pulse_merge.v") +srcs.append("%s.v" % testbench) + +src = ' '.join(srcs) + +build_cmd = "iverilog -o %s.vvp %s" % (testbench, src) + +def bench(): + + # Parameters + + + # Inputs + clk = Signal(bool(0)) + rst = Signal(bool(0)) + current_test = Signal(intbv(0)[8:]) + + m_axis_rq_tready = Signal(bool(0)) + s_axis_rc_tdata = Signal(intbv(0)[256:]) + s_axis_rc_tkeep = Signal(intbv(0)[8:]) + s_axis_rc_tlast = Signal(bool(0)) + s_axis_rc_tuser = Signal(intbv(0)[75:]) + s_axis_rc_tvalid = Signal(bool(0)) + s_axis_cq_tdata = Signal(intbv(0)[256:]) + s_axis_cq_tkeep = Signal(intbv(0)[8:]) + s_axis_cq_tlast = Signal(bool(0)) + s_axis_cq_tuser = Signal(intbv(0)[85:]) + s_axis_cq_tvalid = Signal(bool(0)) + m_axis_cc_tready = Signal(bool(0)) + cfg_max_payload = Signal(intbv(0)[3:]) + cfg_max_read_req = Signal(intbv(0)[3:]) + cfg_mgmt_read_data = Signal(intbv(0)[32:]) + cfg_mgmt_read_write_done = Signal(bool(0)) + cfg_interrupt_msi_enable = Signal(intbv(0)[4:]) + cfg_interrupt_msi_vf_enable = Signal(intbv(0)[8:]) + cfg_interrupt_msi_mmenable = Signal(intbv(0)[12:]) + cfg_interrupt_msi_mask_update = Signal(bool(0)) + cfg_interrupt_msi_data = Signal(intbv(0)[32:]) + cfg_interrupt_msi_sent = Signal(bool(0)) + cfg_interrupt_msi_fail = Signal(bool(0)) + + # Outputs + sfp_1_led = Signal(intbv(0)[2:]) + sfp_2_led = Signal(intbv(0)[2:]) + sma_led = Signal(intbv(0)[2:]) + m_axis_rq_tdata = Signal(intbv(0)[256:]) + m_axis_rq_tkeep = Signal(intbv(0)[8:]) + m_axis_rq_tlast = Signal(bool(0)) + m_axis_rq_tuser = Signal(intbv(0)[60:]) + m_axis_rq_tvalid = Signal(bool(0)) + s_axis_rc_tready = Signal(bool(0)) + s_axis_cq_tready = Signal(bool(0)) + m_axis_cc_tdata = Signal(intbv(0)[256:]) + m_axis_cc_tkeep = Signal(intbv(0)[8:]) + m_axis_cc_tlast = Signal(bool(0)) + m_axis_cc_tuser = Signal(intbv(0)[33:]) + m_axis_cc_tvalid = Signal(bool(0)) + status_error_cor = Signal(bool(0)) + status_error_uncor = Signal(bool(0)) + cfg_mgmt_addr = Signal(intbv(0)[19:]) + cfg_mgmt_write = Signal(bool(0)) + cfg_mgmt_write_data = Signal(intbv(0)[32:]) + cfg_mgmt_byte_enable = Signal(intbv(0)[4:]) + cfg_mgmt_read = Signal(bool(0)) + cfg_interrupt_msi_int = Signal(intbv(0)[32:]) + cfg_interrupt_msi_pending_status = Signal(intbv(0)[32:]) + cfg_interrupt_msi_select = Signal(intbv(0)[4:]) + cfg_interrupt_msi_pending_status_function_num = Signal(intbv(0)[4:]) + cfg_interrupt_msi_pending_status_data_enable = Signal(bool(0)) + cfg_interrupt_msi_attr = Signal(intbv(0)[3:]) + cfg_interrupt_msi_tph_present = Signal(bool(0)) + cfg_interrupt_msi_tph_type = Signal(intbv(0)[2:]) + cfg_interrupt_msi_tph_st_tag = Signal(intbv(0)[9:]) + cfg_interrupt_msi_function_number = Signal(intbv(0)[4:]) + + # Clock and Reset Interface + user_clk=Signal(bool(0)) + user_reset=Signal(bool(0)) + sys_clk=Signal(bool(0)) + sys_reset=Signal(bool(0)) + + # PCIe devices + rc = pcie.RootComplex() + + mem_base, mem_data = rc.alloc_region(16*1024*1024) + + dev = pcie_us.UltrascalePCIe() + + dev.pcie_generation = 3 + dev.pcie_link_width = 8 + dev.user_clock_frequency = 256e6 + + dev.functions[0].msi_multiple_message_capable = 5 + + dev.functions[0].configure_bar(0, 4*1024*1024) + dev.functions[0].configure_bar(1, 4*1024*1024) + + rc.make_port().connect(dev) + + pcie_logic = dev.create_logic( + # Completer reQuest Interface + m_axis_cq_tdata=s_axis_cq_tdata, + m_axis_cq_tuser=s_axis_cq_tuser, + m_axis_cq_tlast=s_axis_cq_tlast, + m_axis_cq_tkeep=s_axis_cq_tkeep, + m_axis_cq_tvalid=s_axis_cq_tvalid, + m_axis_cq_tready=s_axis_cq_tready, + #pcie_cq_np_req=pcie_cq_np_req, + pcie_cq_np_req=Signal(bool(1)), + #pcie_cq_np_req_count=pcie_cq_np_req_count, + + # Completer Completion Interface + s_axis_cc_tdata=m_axis_cc_tdata, + s_axis_cc_tuser=m_axis_cc_tuser, + s_axis_cc_tlast=m_axis_cc_tlast, + s_axis_cc_tkeep=m_axis_cc_tkeep, + s_axis_cc_tvalid=m_axis_cc_tvalid, + s_axis_cc_tready=m_axis_cc_tready, + + # Requester reQuest Interface + s_axis_rq_tdata=m_axis_rq_tdata, + s_axis_rq_tuser=m_axis_rq_tuser, + s_axis_rq_tlast=m_axis_rq_tlast, + s_axis_rq_tkeep=m_axis_rq_tkeep, + s_axis_rq_tvalid=m_axis_rq_tvalid, + s_axis_rq_tready=m_axis_rq_tready, + #pcie_rq_seq_num=pcie_rq_seq_num, + #pcie_rq_seq_num_vld=pcie_rq_seq_num_vld, + #pcie_rq_tag=pcie_rq_tag, + #pcie_rq_tag_vld=pcie_rq_tag_vld, + + # Requester Completion Interface + m_axis_rc_tdata=s_axis_rc_tdata, + m_axis_rc_tuser=s_axis_rc_tuser, + m_axis_rc_tlast=s_axis_rc_tlast, + m_axis_rc_tkeep=s_axis_rc_tkeep, + m_axis_rc_tvalid=s_axis_rc_tvalid, + m_axis_rc_tready=s_axis_rc_tready, + + # Transmit Flow Control Interface + #pcie_tfc_nph_av=pcie_tfc_nph_av, + #pcie_tfc_npd_av=pcie_tfc_npd_av, + + # Configuration Management Interface + cfg_mgmt_addr=cfg_mgmt_addr, + cfg_mgmt_write=cfg_mgmt_write, + cfg_mgmt_write_data=cfg_mgmt_write_data, + cfg_mgmt_byte_enable=cfg_mgmt_byte_enable, + cfg_mgmt_read=cfg_mgmt_read, + cfg_mgmt_read_data=cfg_mgmt_read_data, + cfg_mgmt_read_write_done=cfg_mgmt_read_write_done, + #cfg_mgmt_type1_cfg_reg_access=cfg_mgmt_type1_cfg_reg_access, + + # Configuration Status Interface + #cfg_phy_link_down=cfg_phy_link_down, + #cfg_phy_link_status=cfg_phy_link_status, + #cfg_negotiated_width=cfg_negotiated_width, + #cfg_current_speed=cfg_current_speed, + cfg_max_payload=cfg_max_payload, + cfg_max_read_req=cfg_max_read_req, + #cfg_function_status=cfg_function_status, + #cfg_vf_status=cfg_vf_status, + #cfg_function_power_state=cfg_function_power_state, + #cfg_vf_power_state=cfg_vf_power_state, + #cfg_link_power_state=cfg_link_power_state, + #cfg_err_cor_out=cfg_err_cor_out, + #cfg_err_nonfatal_out=cfg_err_nonfatal_out, + #cfg_err_fatal_out=cfg_err_fatal_out, + #cfg_ltr_enable=cfg_ltr_enable, + #cfg_ltssm_state=cfg_ltssm_state, + #cfg_rcb_status=cfg_rcb_status, + #cfg_dpa_substate_change=cfg_dpa_substate_change, + #cfg_obff_enable=cfg_obff_enable, + #cfg_pl_status_change=cfg_pl_status_change, + #cfg_tph_requester_enable=cfg_tph_requester_enable, + #cfg_tph_st_mode=cfg_tph_st_mode, + #cfg_vf_tph_requester_enable=cfg_vf_tph_requester_enable, + #cfg_vf_tph_st_mode=cfg_vf_tph_st_mode, + + # Configuration Received Message Interface + #cfg_msg_received=cfg_msg_received, + #cfg_msg_received_data=cfg_msg_received_data, + #cfg_msg_received_type=cfg_msg_received_type, + + # Configuration Transmit Message Interface + #cfg_msg_transmit=cfg_msg_transmit, + #cfg_msg_transmit_type=cfg_msg_transmit_type, + #cfg_msg_transmit_data=cfg_msg_transmit_data, + #cfg_msg_transmit_done=cfg_msg_transmit_done, + + # Configuration Flow Control Interface + #cfg_fc_ph=cfg_fc_ph, + #cfg_fc_pd=cfg_fc_pd, + #cfg_fc_nph=cfg_fc_nph, + #cfg_fc_npd=cfg_fc_npd, + #cfg_fc_cplh=cfg_fc_cplh, + #cfg_fc_cpld=cfg_fc_cpld, + #cfg_fc_sel=cfg_fc_sel, + + # Per-Function Status Interface + #cfg_per_func_status_control=cfg_per_func_status_control, + #cfg_per_func_status_data=cfg_per_func_status_data, + + # Configuration Control Interface + #cfg_hot_reset_in=cfg_hot_reset_in, + #cfg_hot_reset_out=cfg_hot_reset_out, + #cfg_config_space_enable=cfg_config_space_enable, + #cfg_per_function_update_done=cfg_per_function_update_done, + #cfg_per_function_number=cfg_per_function_number, + #cfg_per_function_output_request=cfg_per_function_output_request, + #cfg_dsn=cfg_dsn, + #cfg_ds_bus_number=cfg_ds_bus_number, + #cfg_ds_device_number=cfg_ds_device_number, + #cfg_ds_function_number=cfg_ds_function_number, + #cfg_power_state_change_ack=cfg_power_state_change_ack, + #cfg_power_state_change_interrupt=cfg_power_state_change_interrupt, + cfg_err_cor_in=status_error_cor, + cfg_err_uncor_in=status_error_uncor, + #cfg_flr_done=cfg_flr_done, + #cfg_vf_flr_done=cfg_vf_flr_done, + #cfg_flr_in_process=cfg_flr_in_process, + #cfg_vf_flr_in_process=cfg_vf_flr_in_process, + #cfg_req_pm_transition_l23_ready=cfg_req_pm_transition_l23_ready, + #cfg_link_training_enable=cfg_link_training_enable, + + # Configuration Interrupt Controller Interface + #cfg_interrupt_int=cfg_interrupt_int, + #cfg_interrupt_sent=cfg_interrupt_sent, + #cfg_interrupt_pending=cfg_interrupt_pending, + cfg_interrupt_msi_enable=cfg_interrupt_msi_enable, + cfg_interrupt_msi_vf_enable=cfg_interrupt_msi_vf_enable, + cfg_interrupt_msi_mmenable=cfg_interrupt_msi_mmenable, + cfg_interrupt_msi_mask_update=cfg_interrupt_msi_mask_update, + cfg_interrupt_msi_data=cfg_interrupt_msi_data, + cfg_interrupt_msi_select=cfg_interrupt_msi_select, + cfg_interrupt_msi_int=cfg_interrupt_msi_int, + cfg_interrupt_msi_pending_status=cfg_interrupt_msi_pending_status, + cfg_interrupt_msi_pending_status_data_enable=cfg_interrupt_msi_pending_status_data_enable, + cfg_interrupt_msi_pending_status_function_num=cfg_interrupt_msi_pending_status_function_num, + cfg_interrupt_msi_sent=cfg_interrupt_msi_sent, + cfg_interrupt_msi_fail=cfg_interrupt_msi_fail, + #cfg_interrupt_msix_enable=cfg_interrupt_msix_enable, + #cfg_interrupt_msix_mask=cfg_interrupt_msix_mask, + #cfg_interrupt_msix_vf_enable=cfg_interrupt_msix_vf_enable, + #cfg_interrupt_msix_vf_mask=cfg_interrupt_msix_vf_mask, + #cfg_interrupt_msix_address=cfg_interrupt_msix_address, + #cfg_interrupt_msix_data=cfg_interrupt_msix_data, + #cfg_interrupt_msix_int=cfg_interrupt_msix_int, + #cfg_interrupt_msix_sent=cfg_interrupt_msix_sent, + #cfg_interrupt_msix_fail=cfg_interrupt_msix_fail, + cfg_interrupt_msi_attr=cfg_interrupt_msi_attr, + cfg_interrupt_msi_tph_present=cfg_interrupt_msi_tph_present, + cfg_interrupt_msi_tph_type=cfg_interrupt_msi_tph_type, + cfg_interrupt_msi_tph_st_tag=cfg_interrupt_msi_tph_st_tag, + cfg_interrupt_msi_function_number=cfg_interrupt_msi_function_number, + + # Configuration Extend Interface + #cfg_ext_read_received=cfg_ext_read_received, + #cfg_ext_write_received=cfg_ext_write_received, + #cfg_ext_register_number=cfg_ext_register_number, + #cfg_ext_function_number=cfg_ext_function_number, + #cfg_ext_write_data=cfg_ext_write_data, + #cfg_ext_write_byte_enable=cfg_ext_write_byte_enable, + #cfg_ext_read_data=cfg_ext_read_data, + #cfg_ext_read_data_valid=cfg_ext_read_data_valid, + + # Clock and Reset Interface + user_clk=user_clk, + user_reset=user_reset, + sys_clk=sys_clk, + sys_clk_gt=sys_clk, + sys_reset=sys_reset, + #pcie_perstn0_out=pcie_perstn0_out, + #pcie_perstn1_in=pcie_perstn1_in, + #pcie_perstn1_out=pcie_perstn1_out + ) + + # DUT + if os.system(build_cmd): + raise Exception("Error running build command") + + dut = Cosimulation( + "vvp -m myhdl %s.vvp -lxt2" % testbench, + clk=user_clk, + rst=user_reset, + current_test=current_test, + sfp_1_led=sfp_1_led, + sfp_2_led=sfp_2_led, + sma_led=sma_led, + m_axis_rq_tdata=m_axis_rq_tdata, + m_axis_rq_tkeep=m_axis_rq_tkeep, + m_axis_rq_tlast=m_axis_rq_tlast, + m_axis_rq_tready=m_axis_rq_tready, + m_axis_rq_tuser=m_axis_rq_tuser, + m_axis_rq_tvalid=m_axis_rq_tvalid, + s_axis_rc_tdata=s_axis_rc_tdata, + s_axis_rc_tkeep=s_axis_rc_tkeep, + s_axis_rc_tlast=s_axis_rc_tlast, + s_axis_rc_tready=s_axis_rc_tready, + s_axis_rc_tuser=s_axis_rc_tuser, + s_axis_rc_tvalid=s_axis_rc_tvalid, + s_axis_cq_tdata=s_axis_cq_tdata, + s_axis_cq_tkeep=s_axis_cq_tkeep, + s_axis_cq_tlast=s_axis_cq_tlast, + s_axis_cq_tready=s_axis_cq_tready, + s_axis_cq_tuser=s_axis_cq_tuser, + s_axis_cq_tvalid=s_axis_cq_tvalid, + m_axis_cc_tdata=m_axis_cc_tdata, + m_axis_cc_tkeep=m_axis_cc_tkeep, + m_axis_cc_tlast=m_axis_cc_tlast, + m_axis_cc_tready=m_axis_cc_tready, + m_axis_cc_tuser=m_axis_cc_tuser, + m_axis_cc_tvalid=m_axis_cc_tvalid, + cfg_max_payload=cfg_max_payload, + cfg_max_read_req=cfg_max_read_req, + cfg_mgmt_addr=cfg_mgmt_addr, + cfg_mgmt_write=cfg_mgmt_write, + cfg_mgmt_write_data=cfg_mgmt_write_data, + cfg_mgmt_byte_enable=cfg_mgmt_byte_enable, + cfg_mgmt_read=cfg_mgmt_read, + cfg_mgmt_read_data=cfg_mgmt_read_data, + cfg_mgmt_read_write_done=cfg_mgmt_read_write_done, + cfg_interrupt_msi_enable=cfg_interrupt_msi_enable, + cfg_interrupt_msi_vf_enable=cfg_interrupt_msi_vf_enable, + cfg_interrupt_msi_int=cfg_interrupt_msi_int, + cfg_interrupt_msi_sent=cfg_interrupt_msi_sent, + cfg_interrupt_msi_fail=cfg_interrupt_msi_fail, + cfg_interrupt_msi_mmenable=cfg_interrupt_msi_mmenable, + cfg_interrupt_msi_pending_status=cfg_interrupt_msi_pending_status, + cfg_interrupt_msi_mask_update=cfg_interrupt_msi_mask_update, + cfg_interrupt_msi_select=cfg_interrupt_msi_select, + cfg_interrupt_msi_data=cfg_interrupt_msi_data, + cfg_interrupt_msi_pending_status_function_num=cfg_interrupt_msi_pending_status_function_num, + cfg_interrupt_msi_pending_status_data_enable=cfg_interrupt_msi_pending_status_data_enable, + cfg_interrupt_msi_attr=cfg_interrupt_msi_attr, + cfg_interrupt_msi_tph_present=cfg_interrupt_msi_tph_present, + cfg_interrupt_msi_tph_type=cfg_interrupt_msi_tph_type, + cfg_interrupt_msi_tph_st_tag=cfg_interrupt_msi_tph_st_tag, + cfg_interrupt_msi_function_number=cfg_interrupt_msi_function_number, + status_error_cor=status_error_cor, + status_error_uncor=status_error_uncor + ) + + @always(delay(5)) + def clkgen(): + clk.next = not clk + + @always_comb + def clk_logic(): + sys_clk.next = clk + sys_reset.next = not rst + + @instance + def check(): + yield delay(100) + yield clk.posedge + rst.next = 1 + yield clk.posedge + rst.next = 0 + yield clk.posedge + yield delay(100) + yield clk.posedge + + # testbench stimulus + + current_tag = 1 + + yield clk.posedge + print("test 1: enumeration") + current_test.next = 1 + + yield rc.enumerate(enable_bus_mastering=True, configure_msi=True) + + dev_pf0_bar0 = dev.functions[0].bar[0] & 0xfffffffc + dev_pf0_bar1 = dev.functions[0].bar[1] & 0xfffffffc + + yield delay(100) + + yield clk.posedge + print("test 2: memory write to bar 1") + current_test.next = 2 + + yield rc.mem_write(dev_pf0_bar1, b'\x11\x22\x33\x44') + + yield delay(100) + + yield clk.posedge + print("test 3: memory read from bar 1") + current_test.next = 3 + + val = yield from rc.mem_read(dev_pf0_bar1, 4, 1000) + print(val) + assert val == b'\x11\x22\x33\x44' + + yield delay(100) + + yield clk.posedge + print("test 4: test DMA") + current_test.next = 4 + + # write packet data + mem_data[0:1024] = bytearray([x%256 for x in range(1024)]) + + # enable DMA + yield rc.mem_write(dev_pf0_bar0+0x100000, struct.pack('> 32) & 0xffffffff)) + yield rc.mem_write(dev_pf0_bar0+0x100108, struct.pack('> 32) & 0xffffffff)) + yield rc.mem_write(dev_pf0_bar0+0x100110, struct.pack('> 32) & 0xffffffff)) + yield rc.mem_write(dev_pf0_bar0+0x100208, struct.pack('> 32) & 0xffffffff)) + yield rc.mem_write(dev_pf0_bar0+0x100210, struct.pack('