Add Batch 8 with 10 repos
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- BerkeleyLab_Bedrock/.github/workflows/build.yml +61 -0
- BerkeleyLab_Bedrock/.gitlab-ci.yml +57 -0
- BerkeleyLab_Bedrock/.gitlab/ci/badger.gitlab-ci.yml +62 -0
- BerkeleyLab_Bedrock/.gitlab/ci/board_support.gitlab-ci.yml +8 -0
- BerkeleyLab_Bedrock/.gitlab/ci/build.gitlab-ci.yml +111 -0
- BerkeleyLab_Bedrock/.gitlab/ci/cdc_check.gitlab-ci.yml +13 -0
- BerkeleyLab_Bedrock/.gitlab/ci/cmoc.gitlab-ci.yml +56 -0
- BerkeleyLab_Bedrock/.gitlab/ci/comms_top.gitlab-ci.yml +70 -0
- BerkeleyLab_Bedrock/.gitlab/ci/ctrace.gitlab-ci.yml +6 -0
- BerkeleyLab_Bedrock/.gitlab/ci/docs.gitlab-ci.yml +33 -0
- BerkeleyLab_Bedrock/.gitlab/ci/dsp.gitlab-ci.yml +60 -0
- BerkeleyLab_Bedrock/.gitlab/ci/localbus.gitlab-ci.yml +6 -0
- BerkeleyLab_Bedrock/.gitlab/ci/marble_family.gitlab-ci.yml +97 -0
- BerkeleyLab_Bedrock/.gitlab/ci/oscope.gitlab-ci.yml +97 -0
- BerkeleyLab_Bedrock/.gitlab/ci/other_hdl.gitlab-ci.yml +35 -0
- BerkeleyLab_Bedrock/.gitlab/ci/serial_io.gitlab-ci.yml +8 -0
- BerkeleyLab_Bedrock/.gitlab/ci/soc.gitlab-ci.yml +57 -0
- BerkeleyLab_Bedrock/.gitlab/ci/swap_gitid.gitlab-ci.yml +8 -0
- BerkeleyLab_Bedrock/CONTRIBUTING.md +251 -0
- BerkeleyLab_Bedrock/LICENSE.md +21 -0
- BerkeleyLab_Bedrock/README.md +107 -0
- BerkeleyLab_Bedrock/badger/README.md +179 -0
- BerkeleyLab_Bedrock/badger/base_rx_mac.v +46 -0
- BerkeleyLab_Bedrock/badger/collect_clients.py +112 -0
- BerkeleyLab_Bedrock/badger/construct.v +204 -0
- BerkeleyLab_Bedrock/badger/crc8e_guts.v +66 -0
- BerkeleyLab_Bedrock/badger/doc/README.md +29 -0
- BerkeleyLab_Bedrock/badger/ethernet_crc_add.v +46 -0
- BerkeleyLab_Bedrock/badger/flash.md +134 -0
- BerkeleyLab_Bedrock/badger/hack_icmp_cksum.v +44 -0
- BerkeleyLab_Bedrock/badger/hello.v +27 -0
- BerkeleyLab_Bedrock/badger/lb_gateway.v +58 -0
- BerkeleyLab_Bedrock/badger/lbus_access.py +219 -0
- BerkeleyLab_Bedrock/badger/mac_subset.v +83 -0
- BerkeleyLab_Bedrock/badger/mem_gate.md +211 -0
- BerkeleyLab_Bedrock/badger/mem_gateway.v +145 -0
- BerkeleyLab_Bedrock/badger/ones_chksum.v +28 -0
- BerkeleyLab_Bedrock/badger/packet_categorize.v +41 -0
- BerkeleyLab_Bedrock/badger/pbuf_writer.v +138 -0
- BerkeleyLab_Bedrock/badger/precog.v +77 -0
- BerkeleyLab_Bedrock/badger/rtefi_center.v +300 -0
- BerkeleyLab_Bedrock/badger/rtefi_notes.txt +95 -0
- BerkeleyLab_Bedrock/badger/rtefi_preblob.v +129 -0
- BerkeleyLab_Bedrock/badger/scanner.v +526 -0
- BerkeleyLab_Bedrock/badger/speed_test.v +32 -0
- BerkeleyLab_Bedrock/badger/spi_flash.v +136 -0
- BerkeleyLab_Bedrock/badger/spi_flash_engine.v +146 -0
- BerkeleyLab_Bedrock/badger/status.md +69 -0
- BerkeleyLab_Bedrock/badger/test_tx_mac.v +77 -0
- BerkeleyLab_Bedrock/badger/tests/ac701_rgmii_test.tcl +6 -0
BerkeleyLab_Bedrock/.github/workflows/build.yml
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Bedrock documentation
|
| 2 |
+
|
| 3 |
+
on: [push, pull_request]
|
| 4 |
+
|
| 5 |
+
jobs:
|
| 6 |
+
build:
|
| 7 |
+
# We want to run on external PRs, but not on our own internal PRs as
|
| 8 |
+
# they'll be run by the push to the branch. Without this if check,
|
| 9 |
+
# checks are duplicated since internal PRs match both the push and
|
| 10 |
+
# pull_request events.
|
| 11 |
+
if: >
|
| 12 |
+
github.event_name == 'push' ||
|
| 13 |
+
github.event.pull_request.head.repo.full_name != github.repository
|
| 14 |
+
|
| 15 |
+
runs-on: ubuntu-latest
|
| 16 |
+
|
| 17 |
+
strategy:
|
| 18 |
+
fail-fast: false
|
| 19 |
+
|
| 20 |
+
steps:
|
| 21 |
+
- uses: actions/checkout@v4
|
| 22 |
+
|
| 23 |
+
- name: Setup python
|
| 24 |
+
uses: actions/setup-python@v5
|
| 25 |
+
with:
|
| 26 |
+
python-version: '3.8'
|
| 27 |
+
|
| 28 |
+
- name: Install python PIP packages
|
| 29 |
+
run: |
|
| 30 |
+
python -m pip install \
|
| 31 |
+
sphinx==5.0.2 \
|
| 32 |
+
sphinx_rtd_theme \
|
| 33 |
+
numpy m2r2==0.3.2
|
| 34 |
+
|
| 35 |
+
- name: Install documentation tools
|
| 36 |
+
run: |
|
| 37 |
+
sudo apt-get update
|
| 38 |
+
sudo apt-get -y install make \
|
| 39 |
+
imagemagick ghostscript \
|
| 40 |
+
iverilog xvfb gtkwave \
|
| 41 |
+
texlive-binaries
|
| 42 |
+
sudo sed -i -e '/pattern="PS"/ s/rights=".*" pattern=/rights="read|write" pattern=/g' \
|
| 43 |
+
-e '/pattern="PDF"/ s/rights=".*" pattern=/rights="read|write" pattern=/g' \
|
| 44 |
+
-e '/pattern="EPS"/ s/rights=".*" pattern=/rights="read|write" pattern=/g' \
|
| 45 |
+
-e '/<\/policymap>/i \ <policy domain="coder" rights="read|write" pattern="{GIF,JPEG,PNG,WEBP}" \/>' /etc/ImageMagick-*/policy.xml
|
| 46 |
+
|
| 47 |
+
- name: Build sphinx docs
|
| 48 |
+
run: |
|
| 49 |
+
make -C doc html
|
| 50 |
+
|
| 51 |
+
- name: Deploy gh-pages
|
| 52 |
+
uses: peaceiris/actions-gh-pages@v4
|
| 53 |
+
with:
|
| 54 |
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
| 55 |
+
publish_dir: ./doc/_build/html
|
| 56 |
+
|
| 57 |
+
- name: Upload artifacts
|
| 58 |
+
uses: actions/upload-artifact@v4
|
| 59 |
+
with:
|
| 60 |
+
name: badger-doc
|
| 61 |
+
path: badger/doc/*.svg
|
BerkeleyLab_Bedrock/.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
stages:
|
| 2 |
+
- build
|
| 3 |
+
- test
|
| 4 |
+
- synthesis
|
| 5 |
+
- program
|
| 6 |
+
- docs
|
| 7 |
+
|
| 8 |
+
variables:
|
| 9 |
+
XILINX_VIVADO: /non-free/Xilinx/Vivado/2020.2
|
| 10 |
+
CI_REGISTRY: mohs.dhcp.lbl.gov
|
| 11 |
+
IMAGE_BASE: bedrock_testing_base
|
| 12 |
+
IMAGE_VARIANT: bookworm
|
| 13 |
+
DEFAULT_IMAGE: ${CI_REGISTRY}/${IMAGE_BASE}_${IMAGE_VARIANT}
|
| 14 |
+
DOCKER_HOST: tcp://docker:2375/
|
| 15 |
+
DOCKER_DRIVER: overlay2
|
| 16 |
+
FF_SCRIPT_SECTIONS: "true"
|
| 17 |
+
|
| 18 |
+
# default image if no other specified
|
| 19 |
+
image: $DEFAULT_IMAGE:$CI_COMMIT_REF_NAME
|
| 20 |
+
|
| 21 |
+
.build-images:
|
| 22 |
+
parallel:
|
| 23 |
+
IMAGE_VARIANT: [bookworm, trixie]
|
| 24 |
+
|
| 25 |
+
# build matrix for docker image generation
|
| 26 |
+
.build-matrix:
|
| 27 |
+
variables:
|
| 28 |
+
IMAGE: ${CI_REGISTRY}/${IMAGE_BASE}_${IMAGE_VARIANT}
|
| 29 |
+
DOCKERFILE: Dockerfile.${IMAGE_BASE}_${IMAGE_VARIANT}
|
| 30 |
+
parallel:
|
| 31 |
+
matrix:
|
| 32 |
+
- !reference [.build-images, parallel]
|
| 33 |
+
|
| 34 |
+
include:
|
| 35 |
+
- local: .gitlab/ci/badger.gitlab-ci.yml
|
| 36 |
+
- local: .gitlab/ci/build.gitlab-ci.yml
|
| 37 |
+
- local: .gitlab/ci/board_support.gitlab-ci.yml
|
| 38 |
+
- local: .gitlab/ci/docs.gitlab-ci.yml
|
| 39 |
+
- local: .gitlab/ci/serial_io.gitlab-ci.yml
|
| 40 |
+
- local: .gitlab/ci/other_hdl.gitlab-ci.yml
|
| 41 |
+
- local: .gitlab/ci/soc.gitlab-ci.yml
|
| 42 |
+
- local: .gitlab/ci/oscope.gitlab-ci.yml
|
| 43 |
+
- local: .gitlab/ci/cmoc.gitlab-ci.yml
|
| 44 |
+
- local: .gitlab/ci/comms_top.gitlab-ci.yml
|
| 45 |
+
- local: .gitlab/ci/dsp.gitlab-ci.yml
|
| 46 |
+
- local: .gitlab/ci/marble_family.gitlab-ci.yml
|
| 47 |
+
- local: .gitlab/ci/swap_gitid.gitlab-ci.yml
|
| 48 |
+
- local: .gitlab/ci/cdc_check.gitlab-ci.yml
|
| 49 |
+
- local: .gitlab/ci/localbus.gitlab-ci.yml
|
| 50 |
+
- local: .gitlab/ci/ctrace.gitlab-ci.yml
|
| 51 |
+
|
| 52 |
+
flake8:
|
| 53 |
+
extends: .build-matrix
|
| 54 |
+
image: $IMAGE
|
| 55 |
+
stage: test
|
| 56 |
+
script:
|
| 57 |
+
- find . -name "*.py" -exec flake8 {} +
|
BerkeleyLab_Bedrock/.gitlab/ci/badger.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
badger_test:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
stage: test
|
| 5 |
+
before_script:
|
| 6 |
+
- cd badger/tests && make clean && sh ./tap-setup.sh
|
| 7 |
+
script:
|
| 8 |
+
- make && bash tftp_test.sh && bash speed_check.sh
|
| 9 |
+
|
| 10 |
+
.badger-targets:
|
| 11 |
+
parallel:
|
| 12 |
+
TARGET: [ac701, obsidian]
|
| 13 |
+
|
| 14 |
+
.badger-matrix:
|
| 15 |
+
extends:
|
| 16 |
+
- .build-images
|
| 17 |
+
- .badger-targets
|
| 18 |
+
|
| 19 |
+
.badger-build-matrix:
|
| 20 |
+
variables: !reference [.build-matrix, variables]
|
| 21 |
+
parallel:
|
| 22 |
+
matrix:
|
| 23 |
+
- !reference [.badger-matrix, parallel]
|
| 24 |
+
|
| 25 |
+
.badger-run-matrix:
|
| 26 |
+
variables: !reference [.build-matrix, variables]
|
| 27 |
+
parallel:
|
| 28 |
+
matrix:
|
| 29 |
+
- !reference [.build-images, parallel]
|
| 30 |
+
|
| 31 |
+
badger_top:
|
| 32 |
+
extends: .badger-build-matrix
|
| 33 |
+
image: $IMAGE
|
| 34 |
+
stage: synthesis
|
| 35 |
+
before_script:
|
| 36 |
+
- cd badger/tests && ls /non-free
|
| 37 |
+
script:
|
| 38 |
+
- PATH=$XILINX_VIVADO/bin:$PATH make ${TARGET}_rgmii_vtest.bit
|
| 39 |
+
artifacts:
|
| 40 |
+
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
| 41 |
+
expire_in: 2 days
|
| 42 |
+
paths:
|
| 43 |
+
- badger/tests/_xilinx/${TARGET}_rgmii_test.reports
|
| 44 |
+
- badger/tests/${TARGET}_rgmii_vtest.bit
|
| 45 |
+
|
| 46 |
+
badger_ac701_run:
|
| 47 |
+
extends: .badger-run-matrix
|
| 48 |
+
image: $IMAGE
|
| 49 |
+
stage: program
|
| 50 |
+
tags:
|
| 51 |
+
- deploy
|
| 52 |
+
needs:
|
| 53 |
+
- job: badger_top
|
| 54 |
+
parallel:
|
| 55 |
+
matrix:
|
| 56 |
+
- IMAGE_VARIANT: !reference [.build-images, parallel, IMAGE_VARIANT]
|
| 57 |
+
TARGET: ac701
|
| 58 |
+
artifacts: true
|
| 59 |
+
script:
|
| 60 |
+
- cd badger/tests && test -r ac701_rgmii_vtest.bit && SERIAL_NUM_OPT="-s 210203356870" sh teststand_ac701.sh
|
| 61 |
+
environment: hw_ac701
|
| 62 |
+
resource_group: hw_ac701
|
BerkeleyLab_Bedrock/.gitlab/ci/board_support.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
board_support_test:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
before_script:
|
| 5 |
+
- cd board_support
|
| 6 |
+
stage: test
|
| 7 |
+
script:
|
| 8 |
+
- make -C bmb7_kintex jxj_gate_check
|
BerkeleyLab_Bedrock/.gitlab/ci/build.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
check_rebuild:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: docker:stable
|
| 4 |
+
stage: build
|
| 5 |
+
script: |
|
| 6 |
+
echo "DOCKERFILE=${DOCKERFILE}"
|
| 7 |
+
echo "DOCKER_IMAGE_REBUILD=1" > build.env
|
| 8 |
+
artifacts:
|
| 9 |
+
reports:
|
| 10 |
+
dotenv: build.env
|
| 11 |
+
rules:
|
| 12 |
+
- if: '$CI_COMMIT_BRANCH == "master"'
|
| 13 |
+
- if: $CI_COMMIT_BRANCH
|
| 14 |
+
changes:
|
| 15 |
+
- ${DOCKERFILE}
|
| 16 |
+
- build-tools/litex_meta.sh
|
| 17 |
+
- .gitlab/ci/build.gitlab-ci.yml
|
| 18 |
+
|
| 19 |
+
check_exists:
|
| 20 |
+
extends: .build-matrix
|
| 21 |
+
image: docker:stable
|
| 22 |
+
stage: build
|
| 23 |
+
script: |
|
| 24 |
+
export DOCKER_CLI_EXPERIMENTAL=enabled
|
| 25 |
+
docker manifest inspect $IMAGE:$CI_COMMIT_REF_NAME > /dev/null && \
|
| 26 |
+
DOCKER_IMAGE_EXISTS=1 || DOCKER_IMAGE_EXISTS=0
|
| 27 |
+
echo "DOCKER_IMAGE_EXISTS=${DOCKER_IMAGE_EXISTS}" > build.env
|
| 28 |
+
artifacts:
|
| 29 |
+
reports:
|
| 30 |
+
dotenv: build.env
|
| 31 |
+
|
| 32 |
+
# With Gitlab 16.8 we should be able to do"
|
| 33 |
+
# extends: .build-matrix
|
| 34 |
+
# needs:
|
| 35 |
+
# - job: check_rebuild
|
| 36 |
+
# optional: true
|
| 37 |
+
# parallel:
|
| 38 |
+
# matrix:
|
| 39 |
+
# - IMAGE_VARIANT: ['$[[ matrix.IMAGE_VARIANT ]]']
|
| 40 |
+
# - job: check_exists
|
| 41 |
+
# parallel:
|
| 42 |
+
# matrix:
|
| 43 |
+
# - IMAGE_VARIANT: ['$[[ matrix.IMAGE_VARIANT ]]']
|
| 44 |
+
|
| 45 |
+
.build:
|
| 46 |
+
image: docker:stable
|
| 47 |
+
stage: build
|
| 48 |
+
variables:
|
| 49 |
+
services:
|
| 50 |
+
- name: mohs.dhcp.lbl.gov/docker:29.4.0-dind
|
| 51 |
+
command: ["--insecure-registry", "mohs.dhcp.lbl.gov"]
|
| 52 |
+
alias: docker
|
| 53 |
+
before_script:
|
| 54 |
+
- cat /etc/hosts
|
| 55 |
+
- cat /etc/resolv.conf
|
| 56 |
+
- docker info
|
| 57 |
+
- echo $IMAGE:$CI_COMMIT_REF_NAME
|
| 58 |
+
- echo $IMAGE:$CI_COMMIT_SHORT_SHA
|
| 59 |
+
- echo $IMAGE:$CI_PROJECT_NAME-$CI_COMMIT_SHORT_SHA
|
| 60 |
+
script: |
|
| 61 |
+
echo "DOCKER_IMAGE_REBUILD=${DOCKER_IMAGE_REBUILD}"
|
| 62 |
+
echo "DOCKER_IMAGE_EXISTS=${DOCKER_IMAGE_EXISTS}"
|
| 63 |
+
if [ \( -z "$DOCKER_IMAGE_REBUILD" -o "$DOCKER_IMAGE_REBUILD" == "0" \) -a \
|
| 64 |
+
"$DOCKER_IMAGE_EXISTS" == "1" ]; then
|
| 65 |
+
exit 0
|
| 66 |
+
fi
|
| 67 |
+
IMAGE_BASENAME=${IMAGE##*/}
|
| 68 |
+
docker pull $IMAGE:latest || true
|
| 69 |
+
docker build --cache-from $IMAGE:latest \
|
| 70 |
+
-t $IMAGE:$CI_COMMIT_REF_NAME \
|
| 71 |
+
-t $IMAGE:$CI_PROJECT_NAME-$CI_COMMIT_SHORT_SHA \
|
| 72 |
+
-t $IMAGE:latest \
|
| 73 |
+
-f Dockerfile.${IMAGE_BASENAME} \
|
| 74 |
+
.
|
| 75 |
+
docker run --rm $IMAGE bash -c 'echo -n "Debian version: "; cat "/etc/debian_version"'
|
| 76 |
+
docker push $IMAGE:$CI_COMMIT_REF_NAME
|
| 77 |
+
docker push $IMAGE:$CI_PROJECT_NAME-$CI_COMMIT_SHORT_SHA
|
| 78 |
+
docker push $IMAGE:latest
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
build_bookworm:
|
| 82 |
+
extends: .build
|
| 83 |
+
variables:
|
| 84 |
+
IMAGE_VARIANT: bookworm
|
| 85 |
+
IMAGE: ${CI_REGISTRY}/${IMAGE_BASE}_${IMAGE_VARIANT}
|
| 86 |
+
needs:
|
| 87 |
+
- job: check_rebuild
|
| 88 |
+
optional: true
|
| 89 |
+
parallel:
|
| 90 |
+
matrix:
|
| 91 |
+
- IMAGE_VARIANT: bookworm
|
| 92 |
+
- job: check_exists
|
| 93 |
+
parallel:
|
| 94 |
+
matrix:
|
| 95 |
+
- IMAGE_VARIANT: bookworm
|
| 96 |
+
|
| 97 |
+
build_trixie:
|
| 98 |
+
extends: .build
|
| 99 |
+
variables:
|
| 100 |
+
IMAGE_VARIANT: trixie
|
| 101 |
+
IMAGE: ${CI_REGISTRY}/${IMAGE_BASE}_${IMAGE_VARIANT}
|
| 102 |
+
needs:
|
| 103 |
+
- job: check_rebuild
|
| 104 |
+
optional: true
|
| 105 |
+
parallel:
|
| 106 |
+
matrix:
|
| 107 |
+
- IMAGE_VARIANT: trixie
|
| 108 |
+
- job: check_exists
|
| 109 |
+
parallel:
|
| 110 |
+
matrix:
|
| 111 |
+
- IMAGE_VARIANT: trixie
|
BerkeleyLab_Bedrock/.gitlab/ci/cdc_check.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
badger_cdc:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
stage: test
|
| 5 |
+
script:
|
| 6 |
+
- make -C badger/tests hw_test_cdc.txt
|
| 7 |
+
|
| 8 |
+
marble_cdc:
|
| 9 |
+
extends: .build-matrix
|
| 10 |
+
image: $IMAGE
|
| 11 |
+
stage: test
|
| 12 |
+
script:
|
| 13 |
+
- make -C projects/test_marble_family marble_base_cdc.txt
|
BerkeleyLab_Bedrock/.gitlab/ci/cmoc.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
rtsim_test:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
before_script:
|
| 5 |
+
- cd rtsim && make clean && make
|
| 6 |
+
stage: test
|
| 7 |
+
script:
|
| 8 |
+
- make clean && make checks && make rtsim.dat
|
| 9 |
+
|
| 10 |
+
cmoc_test:
|
| 11 |
+
extends: .build-matrix
|
| 12 |
+
image: $IMAGE
|
| 13 |
+
before_script:
|
| 14 |
+
- cd cmoc
|
| 15 |
+
stage: test
|
| 16 |
+
script:
|
| 17 |
+
- make && make checks
|
| 18 |
+
|
| 19 |
+
# Because Gitlab doesn't support using extends with
|
| 20 |
+
# multiple parallel:matrix + Issue 439828 (https://gitlab.com/gitlab-org/gitlab/-/issues/439828)
|
| 21 |
+
# the following is the best I could think of to merge 2 parallel:matrix lists:
|
| 22 |
+
|
| 23 |
+
# 1. Define the specific dictionary you want
|
| 24 |
+
.marble-targets:
|
| 25 |
+
parallel:
|
| 26 |
+
TARGET: [marblemini, marble]
|
| 27 |
+
|
| 28 |
+
# 2. Merge the above dictionary with tth .build-matrix defined in .gitlab-ci.yml
|
| 29 |
+
# with extends: https://docs.gitlab.com/ci/yaml/yaml_optimization/#merge-details
|
| 30 |
+
.cmoc-top-matrix:
|
| 31 |
+
extends:
|
| 32 |
+
- .build-images
|
| 33 |
+
- .marble-targets
|
| 34 |
+
|
| 35 |
+
# 3. re-build the yaml structure of .build-matrix replacing "parallel:matrix"
|
| 36 |
+
# with the newly created dictionary on 2.
|
| 37 |
+
.cmoc-top-build-matrix:
|
| 38 |
+
variables: !reference [.build-matrix, variables]
|
| 39 |
+
parallel:
|
| 40 |
+
matrix:
|
| 41 |
+
- !reference [.cmoc-top-matrix, parallel]
|
| 42 |
+
|
| 43 |
+
cmoc_top:
|
| 44 |
+
extends: .cmoc-top-build-matrix
|
| 45 |
+
image: $IMAGE
|
| 46 |
+
before_script:
|
| 47 |
+
- cd projects/cmoc_top/marblemini && ls /non-free
|
| 48 |
+
stage: synthesis
|
| 49 |
+
script:
|
| 50 |
+
- XILINX_VIVADO=$XILINX_VIVADO PATH=$XILINX_VIVADO/bin:$PATH make HARDWARE=${TARGET} cmoc_top.bit
|
| 51 |
+
- mv cmoc_top.bit cmoc_top_${TARGET}.bit
|
| 52 |
+
artifacts:
|
| 53 |
+
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
| 54 |
+
expire_in: 1 week
|
| 55 |
+
paths:
|
| 56 |
+
- projects/cmoc_top/marblemini/cmoc_top_${TARGET}.bit
|
BerkeleyLab_Bedrock/.gitlab/ci/comms_top.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
comms_top:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
before_script:
|
| 5 |
+
- cd projects/comms_top && ls /non-free
|
| 6 |
+
stage: synthesis
|
| 7 |
+
script:
|
| 8 |
+
- PATH=$XILINX_VIVADO/bin:$PATH make comms_top.bit
|
| 9 |
+
artifacts:
|
| 10 |
+
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
| 11 |
+
expire_in: 1 week
|
| 12 |
+
paths:
|
| 13 |
+
- projects/comms_top/comms_top.bit
|
| 14 |
+
|
| 15 |
+
comms_top_run:
|
| 16 |
+
extends: .build-matrix
|
| 17 |
+
image: $IMAGE
|
| 18 |
+
stage: program
|
| 19 |
+
tags:
|
| 20 |
+
- deploy
|
| 21 |
+
dependencies:
|
| 22 |
+
- comms_top
|
| 23 |
+
script:
|
| 24 |
+
- cd projects/comms_top
|
| 25 |
+
- sh qf2_070_3_setup.sh
|
| 26 |
+
- make QF2_TOOLS=qf2-pre-users QF2_IP=192.168.1.30 hwload && sleep 8 && make hwtest
|
| 27 |
+
environment: hw_qf2_pre
|
| 28 |
+
resource_group: hw_qf2_pre
|
| 29 |
+
|
| 30 |
+
.doublebit-targets:
|
| 31 |
+
parallel:
|
| 32 |
+
DOUBLEBIT: ["0", "1"]
|
| 33 |
+
|
| 34 |
+
.gige-top-matrix:
|
| 35 |
+
extends:
|
| 36 |
+
- .build-images
|
| 37 |
+
- .doublebit-targets
|
| 38 |
+
|
| 39 |
+
.gige-top-build-matrix:
|
| 40 |
+
variables: !reference [.build-matrix, variables]
|
| 41 |
+
parallel:
|
| 42 |
+
matrix:
|
| 43 |
+
- !reference [.gige-top-matrix, parallel]
|
| 44 |
+
|
| 45 |
+
gige_sfp_ac701:
|
| 46 |
+
extends: .gige-top-build-matrix
|
| 47 |
+
image: $IMAGE
|
| 48 |
+
stage: synthesis
|
| 49 |
+
before_script:
|
| 50 |
+
- cd projects/comms_top/gige_eth && ls /non-free
|
| 51 |
+
script:
|
| 52 |
+
- PATH=$XILINX_VIVADO/bin:$PATH make HARDWARE=ac701 DOUBLEBIT=$DOUBLEBIT gige_top.bit
|
| 53 |
+
artifacts:
|
| 54 |
+
name: "$CI_JOB_NAME-DB$DOUBLEBIT-$CI_COMMIT_REF_NAME"
|
| 55 |
+
expire_in: 1 week
|
| 56 |
+
paths:
|
| 57 |
+
- projects/comms_top/gige_eth/gige_top.bit
|
| 58 |
+
|
| 59 |
+
gige_sfp_ac701_run:
|
| 60 |
+
extends: .gige-top-build-matrix
|
| 61 |
+
image: $IMAGE
|
| 62 |
+
stage: program
|
| 63 |
+
tags:
|
| 64 |
+
- deploy
|
| 65 |
+
needs:
|
| 66 |
+
- job: gige_sfp_ac701
|
| 67 |
+
script:
|
| 68 |
+
- cd projects/comms_top/gige_eth && make hwload_ac701 SERIAL_NUM_OPT="-s 210203356870" && sleep 7 && make hwtest_ac701
|
| 69 |
+
environment: hw_ac701
|
| 70 |
+
resource_group: hw_ac701
|
BerkeleyLab_Bedrock/.gitlab/ci/ctrace.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ctrace_test:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
stage: test
|
| 5 |
+
script:
|
| 6 |
+
- make -C projects/ctrace
|
BerkeleyLab_Bedrock/.gitlab/ci/docs.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
make_docs:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
before_script:
|
| 5 |
+
- cd build-tools/make-demo && make clean
|
| 6 |
+
stage: test
|
| 7 |
+
script:
|
| 8 |
+
- make check consistency
|
| 9 |
+
|
| 10 |
+
sphinx_docs:
|
| 11 |
+
extends: .build-matrix
|
| 12 |
+
image: $IMAGE
|
| 13 |
+
stage: docs
|
| 14 |
+
before_script: |
|
| 15 |
+
apt-get update
|
| 16 |
+
apt-get install -y \
|
| 17 |
+
imagemagick \
|
| 18 |
+
ghostscript \
|
| 19 |
+
xvfb \
|
| 20 |
+
gtkwave \
|
| 21 |
+
texlive-binaries
|
| 22 |
+
python3 -m pip install \
|
| 23 |
+
standard-imghdr \
|
| 24 |
+
sphinx==8.1.3 \
|
| 25 |
+
sphinx_rtd_theme \
|
| 26 |
+
m2r2==0.3.4
|
| 27 |
+
sed -i -e '/pattern="PS"/ s/rights=".*" pattern=/rights="read|write" pattern=/g' \
|
| 28 |
+
-e '/pattern="PDF"/ s/rights=".*" pattern=/rights="read|write" pattern=/g' \
|
| 29 |
+
-e '/pattern="EPS"/ s/rights=".*" pattern=/rights="read|write" pattern=/g' \
|
| 30 |
+
-e '/<\/policymap>/i \ <policy domain="coder" rights="read|write" pattern="{GIF,JPEG,PNG,WEBP}" \/>' \
|
| 31 |
+
/etc/ImageMagick-*/policy.xml
|
| 32 |
+
script:
|
| 33 |
+
- make -C doc html
|
BerkeleyLab_Bedrock/.gitlab/ci/dsp.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
dsp_test:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
before_script:
|
| 5 |
+
- cd dsp
|
| 6 |
+
stage: test
|
| 7 |
+
script:
|
| 8 |
+
- make && make checks
|
| 9 |
+
|
| 10 |
+
dsp_hosted_test:
|
| 11 |
+
extends: .build-matrix
|
| 12 |
+
image: $IMAGE
|
| 13 |
+
before_script:
|
| 14 |
+
- cd dsp/hosted && export PYTHONPATH=../../build-tools/
|
| 15 |
+
stage: test
|
| 16 |
+
script:
|
| 17 |
+
- make && make checks
|
| 18 |
+
artifacts:
|
| 19 |
+
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
| 20 |
+
expire_in: 1 week
|
| 21 |
+
paths:
|
| 22 |
+
- dsp/hosted/fdbk_core_plot.pdf
|
| 23 |
+
|
| 24 |
+
digaree_test:
|
| 25 |
+
extends: .build-matrix
|
| 26 |
+
image: $IMAGE
|
| 27 |
+
before_script:
|
| 28 |
+
- cd dsp/digaree
|
| 29 |
+
stage: test
|
| 30 |
+
script:
|
| 31 |
+
- make
|
| 32 |
+
|
| 33 |
+
feedforward_test:
|
| 34 |
+
extends: .build-matrix
|
| 35 |
+
image: $IMAGE
|
| 36 |
+
before_script:
|
| 37 |
+
- cd dsp/feedforward
|
| 38 |
+
stage: test
|
| 39 |
+
script:
|
| 40 |
+
- make
|
| 41 |
+
|
| 42 |
+
chirp_test:
|
| 43 |
+
extends: .build-matrix
|
| 44 |
+
image: $IMAGE
|
| 45 |
+
before_script:
|
| 46 |
+
- cd dsp/chirp
|
| 47 |
+
stage: test
|
| 48 |
+
script:
|
| 49 |
+
- make && make checks
|
| 50 |
+
|
| 51 |
+
cocotb_test:
|
| 52 |
+
# includes all cocotb testbenches in dsp
|
| 53 |
+
extends: .build-matrix
|
| 54 |
+
image: $IMAGE
|
| 55 |
+
before_script:
|
| 56 |
+
- cd dsp
|
| 57 |
+
stage: test
|
| 58 |
+
script:
|
| 59 |
+
- make TESTBENCH=cic_simple_s_tb -f Makefile_cocotb
|
| 60 |
+
- make TESTBENCH=dds_tb -f Makefile_cocotb
|
BerkeleyLab_Bedrock/.gitlab/ci/localbus.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
localbus:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
stage: test
|
| 5 |
+
script:
|
| 6 |
+
- make -C localbus
|
BerkeleyLab_Bedrock/.gitlab/ci/marble_family.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
marble_sim:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
stage: test
|
| 5 |
+
script:
|
| 6 |
+
- make -C projects/test_marble_family all net_slave_check
|
| 7 |
+
- make -C projects/test_marble_family/pps_lock
|
| 8 |
+
|
| 9 |
+
marble_i2c_check:
|
| 10 |
+
extends: .build-matrix
|
| 11 |
+
image: $IMAGE
|
| 12 |
+
stage: test
|
| 13 |
+
script:
|
| 14 |
+
- make -C projects/test_marble_family/i2c tests
|
| 15 |
+
|
| 16 |
+
.bitgen:
|
| 17 |
+
stage: synthesis
|
| 18 |
+
before_script:
|
| 19 |
+
- cd projects/test_marble_family && ls /non-free
|
| 20 |
+
artifacts:
|
| 21 |
+
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
| 22 |
+
expire_in: 2 days
|
| 23 |
+
|
| 24 |
+
.synth_base:
|
| 25 |
+
extends:
|
| 26 |
+
- .build-matrix
|
| 27 |
+
- .bitgen
|
| 28 |
+
image: $IMAGE
|
| 29 |
+
script:
|
| 30 |
+
- PATH=$XILINX_VIVADO/bin:$PATH make CONFIG=${CONFIG} bit
|
| 31 |
+
artifacts:
|
| 32 |
+
paths:
|
| 33 |
+
- projects/test_marble_family/marble*.bit
|
| 34 |
+
- projects/test_marble_family/vivado.log
|
| 35 |
+
- projects/test_marble_family/_xilinx/${CONFIG}.runs/*.rpt
|
| 36 |
+
- projects/test_marble_family/_xilinx/${CONFIG}.runs/synth_1/marble_top_*.rpt
|
| 37 |
+
- projects/test_marble_family/_xilinx/${CONFIG}.runs/impl_1/marble_top_*.rpt
|
| 38 |
+
|
| 39 |
+
marble_mini_synth:
|
| 40 |
+
extends: .synth_base
|
| 41 |
+
variables:
|
| 42 |
+
CONFIG: marblemini
|
| 43 |
+
|
| 44 |
+
marble_v2_synth:
|
| 45 |
+
extends: .synth_base
|
| 46 |
+
variables:
|
| 47 |
+
CONFIG: marble
|
| 48 |
+
|
| 49 |
+
marble_fiber_synth:
|
| 50 |
+
extends: .synth_base
|
| 51 |
+
variables:
|
| 52 |
+
CONFIG: marble_fiber
|
| 53 |
+
|
| 54 |
+
.run_base:
|
| 55 |
+
extends: .build-matrix
|
| 56 |
+
image: $IMAGE
|
| 57 |
+
stage: program
|
| 58 |
+
tags:
|
| 59 |
+
- deploy
|
| 60 |
+
before_script:
|
| 61 |
+
- cd projects/test_marble_family && ln -s ${CONFIG}.*.bit ${CONFIG}.bit
|
| 62 |
+
script:
|
| 63 |
+
- make CONFIG=${CONFIG} hwload ${SERIAL_ARG} && make CONFIG=${CONFIG} hwtest ${SERIAL_ARG}
|
| 64 |
+
- if [ -n "$RUN_I2C" ]; then make -C i2c live_oneshot ${SERIAL_ARG}; fi
|
| 65 |
+
|
| 66 |
+
marble_mini_run:
|
| 67 |
+
extends: .run_base
|
| 68 |
+
dependencies:
|
| 69 |
+
- marble_mini_synth
|
| 70 |
+
environment: hw_marble_mini
|
| 71 |
+
resource_group: hw_marble_mini
|
| 72 |
+
variables:
|
| 73 |
+
CONFIG: marblemini
|
| 74 |
+
SERIAL_ARG: ""
|
| 75 |
+
RUN_I2C: ""
|
| 76 |
+
|
| 77 |
+
marble_run:
|
| 78 |
+
extends: .run_base
|
| 79 |
+
dependencies:
|
| 80 |
+
- marble_v2_synth
|
| 81 |
+
environment: hw_marble
|
| 82 |
+
resource_group: hw_marble
|
| 83 |
+
variables:
|
| 84 |
+
CONFIG: marble
|
| 85 |
+
SERIAL_ARG: "SERIAL=39"
|
| 86 |
+
RUN_I2C: "true"
|
| 87 |
+
|
| 88 |
+
marble_fiber_run:
|
| 89 |
+
extends: .run_base
|
| 90 |
+
dependencies:
|
| 91 |
+
- marble_fiber_synth
|
| 92 |
+
environment: hw_marble
|
| 93 |
+
resource_group: hw_marble
|
| 94 |
+
variables:
|
| 95 |
+
CONFIG: marble_fiber
|
| 96 |
+
SERIAL_ARG: "SERIAL=39"
|
| 97 |
+
RUN_I2C: "true"
|
BerkeleyLab_Bedrock/.gitlab/ci/oscope.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
oscope_top_test:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
before_script:
|
| 5 |
+
- cd projects/oscope/bmb7_cu
|
| 6 |
+
stage: test
|
| 7 |
+
script:
|
| 8 |
+
- make Voscope_top_tb && make Voscope_top_leep && make clean
|
| 9 |
+
|
| 10 |
+
# We know the design doesn't yet get evaluated as CDC-clean, at least in part
|
| 11 |
+
# due to Verilog inout ports being poorly supported by our tools.
|
| 12 |
+
# Please take out the error bypass (echo) if this ever gets fixed.
|
| 13 |
+
oscope_cdc:
|
| 14 |
+
extends: .build-matrix
|
| 15 |
+
image: $IMAGE
|
| 16 |
+
before_script:
|
| 17 |
+
- cd projects/oscope/marble_family
|
| 18 |
+
stage: test
|
| 19 |
+
script:
|
| 20 |
+
- make dep && make oscope_prep_yosys.json && (make oscope_prep_cdc.txt || echo "Found CDC violation, as expected; continuing")
|
| 21 |
+
artifacts:
|
| 22 |
+
expire_in: 1 week
|
| 23 |
+
paths:
|
| 24 |
+
- projects/oscope/marble_family/oscope_prep_cdc.txt
|
| 25 |
+
|
| 26 |
+
oscope_top_bmb7:
|
| 27 |
+
extends: .build-matrix
|
| 28 |
+
image: $IMAGE
|
| 29 |
+
before_script:
|
| 30 |
+
- cd projects/oscope/bmb7_cu && ls /non-free
|
| 31 |
+
stage: synthesis
|
| 32 |
+
script:
|
| 33 |
+
- verilator -V && XILINX_VIVADO=$XILINX_VIVADO PATH=$XILINX_VIVADO/bin:$PATH make oscope_top.bit
|
| 34 |
+
artifacts:
|
| 35 |
+
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
| 36 |
+
expire_in: 1 week
|
| 37 |
+
paths:
|
| 38 |
+
- projects/oscope/bmb7_cu/oscope_top.bit
|
| 39 |
+
|
| 40 |
+
oscope_top_marble:
|
| 41 |
+
extends: .build-matrix
|
| 42 |
+
image: $IMAGE
|
| 43 |
+
before_script:
|
| 44 |
+
- cd projects/oscope/marble_family && ls /non-free
|
| 45 |
+
stage: synthesis
|
| 46 |
+
script:
|
| 47 |
+
- verilator -V && XILINX_VIVADO=$XILINX_VIVADO PATH=$XILINX_VIVADO/bin:$PATH make oscope_top.bit
|
| 48 |
+
artifacts:
|
| 49 |
+
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
| 50 |
+
expire_in: 1 week
|
| 51 |
+
paths:
|
| 52 |
+
- projects/oscope/marble_family/oscope_top.bit
|
| 53 |
+
|
| 54 |
+
# LITEX_INSTALL_PATH is defined in the Docker image
|
| 55 |
+
marble_ddr3_test:
|
| 56 |
+
extends: .build-matrix
|
| 57 |
+
image: $IMAGE
|
| 58 |
+
stage: synthesis
|
| 59 |
+
before_script:
|
| 60 |
+
- cd $LITEX_INSTALL_PATH/litex-boards/litex_boards/targets
|
| 61 |
+
script:
|
| 62 |
+
- XILINXD_LICENSE_FILE=$XILINXD_LICENSE_FILE PATH=$XILINX_VIVADO/bin:$PATH && python3 berkeleylab_marble.py --build
|
| 63 |
+
- echo $CI_PROJECT_DIR
|
| 64 |
+
- cp $LITEX_INSTALL_PATH/litex-boards/litex_boards/targets/build/berkeleylab_marble/gateware/berkeleylab_marble.bit $CI_PROJECT_DIR/
|
| 65 |
+
artifacts:
|
| 66 |
+
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
| 67 |
+
expire_in: 1 week
|
| 68 |
+
when: always
|
| 69 |
+
paths:
|
| 70 |
+
- berkeleylab_marble.bit
|
| 71 |
+
|
| 72 |
+
litex_trigger_capture:
|
| 73 |
+
extends: .build-matrix
|
| 74 |
+
image: $IMAGE
|
| 75 |
+
stage: synthesis
|
| 76 |
+
before_script:
|
| 77 |
+
- cd projects/trigger_capture
|
| 78 |
+
script:
|
| 79 |
+
XILINXD_LICENSE_FILE=$XILINXD_LICENSE_FILE PATH=$XILINX_VIVADO/bin:$PATH && make marble.bit
|
| 80 |
+
artifacts:
|
| 81 |
+
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
| 82 |
+
expire_in: 1 week
|
| 83 |
+
when: always
|
| 84 |
+
paths:
|
| 85 |
+
- projects/trigger_capture/build/marble/gateware/marble.bit
|
| 86 |
+
- projects/trigger_capture/csr.csv
|
| 87 |
+
|
| 88 |
+
# oscope_program:
|
| 89 |
+
# extends: .build-matrix
|
| 90 |
+
# image: $IMAGE
|
| 91 |
+
# before_script:
|
| 92 |
+
# - cd projects/oscope/software/bmb7 && wget -r -nH http://sliderule.dhcp.lbl.gov:8000/{r1,configuration} && cd ..
|
| 93 |
+
# stage: program
|
| 94 |
+
# dependencies:
|
| 95 |
+
# - oscope_top_bmb7
|
| 96 |
+
# script:
|
| 97 |
+
# - export PYTHONPATH=$PYTHONPATH:../../../build-tools/:../../../dsp && python3 prc.py -a 192.168.1.121 -r -b ../bmb7_cu/oscope_top.bit
|
BerkeleyLab_Bedrock/.gitlab/ci/other_hdl.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# grab-bag of other Verilog/HDL simulation tests
|
| 2 |
+
|
| 3 |
+
cordic_test:
|
| 4 |
+
extends: .build-matrix
|
| 5 |
+
image: $IMAGE
|
| 6 |
+
before_script:
|
| 7 |
+
- cd cordic && make clean
|
| 8 |
+
stage: test
|
| 9 |
+
script:
|
| 10 |
+
- make all
|
| 11 |
+
|
| 12 |
+
freq_demo:
|
| 13 |
+
extends: .build-matrix
|
| 14 |
+
image: $IMAGE
|
| 15 |
+
stage: test
|
| 16 |
+
script:
|
| 17 |
+
- make -C homeless/freq_demo
|
| 18 |
+
- make -C homeless all checks
|
| 19 |
+
|
| 20 |
+
peripheral_test:
|
| 21 |
+
extends: .build-matrix
|
| 22 |
+
image: $IMAGE
|
| 23 |
+
stage: test
|
| 24 |
+
script:
|
| 25 |
+
- make -C peripheral_drivers
|
| 26 |
+
- make -C peripheral_drivers/idelay_scanner
|
| 27 |
+
- make -C peripheral_drivers/ds1822
|
| 28 |
+
- make -C peripheral_drivers/i2cbridge
|
| 29 |
+
|
| 30 |
+
xilinx_test:
|
| 31 |
+
extends: .build-matrix
|
| 32 |
+
image: $IMAGE
|
| 33 |
+
stage: test
|
| 34 |
+
script:
|
| 35 |
+
- make -C fpga_family/xilinx
|
BerkeleyLab_Bedrock/.gitlab/ci/serial_io.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
serial_io_test:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
before_script:
|
| 5 |
+
- cd serial_io
|
| 6 |
+
stage: test
|
| 7 |
+
script:
|
| 8 |
+
- make && make checks && cd chitchat && make && make checks && cd - && cd EVG_EVR && make
|
BerkeleyLab_Bedrock/.gitlab/ci/soc.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
soc_picorv32_test:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
before_script:
|
| 5 |
+
- cd soc/picorv32/test
|
| 6 |
+
stage: test
|
| 7 |
+
script:
|
| 8 |
+
- make
|
| 9 |
+
|
| 10 |
+
# soc_picorv32_unisims_test:
|
| 11 |
+
# before_script:
|
| 12 |
+
# - cd soc/picorv32/test/zest
|
| 13 |
+
# stage: test
|
| 14 |
+
# script:
|
| 15 |
+
# - XILINX_VIVADO=/non-free/Xilinx/Vivado/2019.1 PATH=$XILINX_VIVADO/bin:$PATH make
|
| 16 |
+
|
| 17 |
+
soc_picorv32_kc705:
|
| 18 |
+
extends: .build-matrix
|
| 19 |
+
image: $IMAGE
|
| 20 |
+
stage: synthesis
|
| 21 |
+
before_script:
|
| 22 |
+
- cd soc/picorv32/project/kc705/synth
|
| 23 |
+
script:
|
| 24 |
+
# Run kc705 with older version of Vivado that has suport to non-webpack FPGAs
|
| 25 |
+
- XILINXD_LICENSE_FILE=$XILINXD_LICENSE_FILE XILINX_VIVADO=/non-free/Xilinx/Vivado/2018.3 PATH=$XILINX_VIVADO/bin:$PATH make system_top.bit
|
| 26 |
+
artifacts:
|
| 27 |
+
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
| 28 |
+
expire_in: 1 week
|
| 29 |
+
paths:
|
| 30 |
+
- soc/picorv32/project/kc705/synth/system_top.bit
|
| 31 |
+
|
| 32 |
+
soc_picorv32_cmod_a7:
|
| 33 |
+
extends: .build-matrix
|
| 34 |
+
image: $IMAGE
|
| 35 |
+
stage: synthesis
|
| 36 |
+
before_script:
|
| 37 |
+
- cd soc/picorv32/project/cmod_a7/synth
|
| 38 |
+
script:
|
| 39 |
+
- PATH=$XILINX_VIVADO/bin:$PATH make system_top.bit
|
| 40 |
+
artifacts:
|
| 41 |
+
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
|
| 42 |
+
expire_in: 1 week
|
| 43 |
+
paths:
|
| 44 |
+
- soc/picorv32/project/cmod_a7/synth/system_top.bit
|
| 45 |
+
|
| 46 |
+
soc_picorv32_cmod_a7_run:
|
| 47 |
+
extends: .build-matrix
|
| 48 |
+
image: $IMAGE
|
| 49 |
+
stage: program
|
| 50 |
+
dependencies:
|
| 51 |
+
- soc_picorv32_cmod_a7
|
| 52 |
+
before_script:
|
| 53 |
+
- cd soc/picorv32/project/cmod_a7
|
| 54 |
+
script:
|
| 55 |
+
- xc3sprog -c jtaghs1_fast -s 210328A6DA47 synth/system_top.bit && python3 hw_test.py 210328A6DA47
|
| 56 |
+
environment: hw_cmod_a7
|
| 57 |
+
resource_group: hw_cmod_a7
|
BerkeleyLab_Bedrock/.gitlab/ci/swap_gitid.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
swap_gitid_test:
|
| 2 |
+
extends: .build-matrix
|
| 3 |
+
image: $IMAGE
|
| 4 |
+
before_script:
|
| 5 |
+
- cd build-tools/vivado_tcl
|
| 6 |
+
stage: test
|
| 7 |
+
script:
|
| 8 |
+
- tclsh test_swap_gitid.tcl
|
BerkeleyLab_Bedrock/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Contributing Guidelines
|
| 2 |
+
|
| 3 |
+
Entails contribution guidelines to all projects in the group hdl-libraries.
|
| 4 |
+
We are actively looking for meaningful contributions to our codebase. A
|
| 5 |
+
meaningful contribution can entail anything from:
|
| 6 |
+
|
| 7 |
+
1. A typo
|
| 8 |
+
2. A readability enhancement
|
| 9 |
+
3. A code or Makefile simplification
|
| 10 |
+
4. A bug report
|
| 11 |
+
5. A test
|
| 12 |
+
6. A new source file that you deem fits into this codebase and
|
| 13 |
+
preferably a test that goes with it!
|
| 14 |
+
7. Support for a new board or a chip on the existing projects
|
| 15 |
+
8. A new project
|
| 16 |
+
9. A new way to build code within the code base
|
| 17 |
+
10. New synthesis or simulation framework
|
| 18 |
+
|
| 19 |
+
## TL;DR
|
| 20 |
+
|
| 21 |
+
### Adding a small feature?
|
| 22 |
+
|
| 23 |
+
1. Create a branch, and write code following guidelines here
|
| 24 |
+
2. Add tests
|
| 25 |
+
3. Add them to CI, and ensure they are passing with all the other tests you may have inadvertently broken
|
| 26 |
+
4. Make a pull request and have somebody else other than you merge it into master
|
| 27 |
+
5. Feel free to request for help during any stage
|
| 28 |
+
|
| 29 |
+
### Adding a large feature?
|
| 30 |
+
|
| 31 |
+
1. Start an issue or a wiki link with a detailed feature description/request
|
| 32 |
+
2. Obtain general consensus or feedback
|
| 33 |
+
3. Create a branch, and start a Merge/Pull Request at an early stage, in order to get early feedback from community
|
| 34 |
+
4. Add tests
|
| 35 |
+
5. Add them to CI, and ensure they are passing with all the other tests you may have inadvertently broken
|
| 36 |
+
6. Add documentation
|
| 37 |
+
7. Feel free to request for help during any stage
|
| 38 |
+
|
| 39 |
+
## Code of Conduct
|
| 40 |
+
|
| 41 |
+
Behavior in this community is always expected to be professional, courteous, and constructive.
|
| 42 |
+
Berkeley Lab in particular mandates support of
|
| 43 |
+
[Inclusion, Diversity, Equity, and Accountability](https://diversity.lbl.gov/).
|
| 44 |
+
Please make all contributors feel welcome, assume good intent, and be considerate of others.
|
| 45 |
+
On-line, that often means re-reading your messages carefully before pressing "send."
|
| 46 |
+
|
| 47 |
+
Our team supports the principles and goals expressed in/by the
|
| 48 |
+
[Contributor Covenant](https://www.contributor-covenant.org/).
|
| 49 |
+
As employees of the University of California, where this project is
|
| 50 |
+
part of our workplace environment, it is not obvious that we have
|
| 51 |
+
the right to unilaterally choose, impose, or enforce such a covenant.
|
| 52 |
+
|
| 53 |
+
## Contents of a repository
|
| 54 |
+
|
| 55 |
+
A source repository should be primarily reserved for source code.
|
| 56 |
+
"The source code for a work means the preferred form of the work for
|
| 57 |
+
making modifications to it."
|
| 58 |
+
|
| 59 |
+
Occasionally binary files will creep in, for example visual images
|
| 60 |
+
for documentation purposes. Each such file demands some note as to
|
| 61 |
+
how it was generated.
|
| 62 |
+
|
| 63 |
+
All checked-in files should be permissively licensed, consistent with
|
| 64 |
+
the [LICENSE.md](LICENSE.md) file.
|
| 65 |
+
|
| 66 |
+
Sometimes files are needed that can be legally downloaded from the public Internet,
|
| 67 |
+
but we either don't have permission to redistribute them, or we have other reasons to
|
| 68 |
+
not want them checked into this repository (all GPL code falls in this category,
|
| 69 |
+
due to guidance from University of California lawyers). It's OK to script the
|
| 70 |
+
download of these files; please include a check that the result has the expected
|
| 71 |
+
[SHA256](https://en.wikipedia.org/wiki/SHA-2). Do NOT redistribute or embed
|
| 72 |
+
any files within Bedrock unless they have a suitably permissive license.
|
| 73 |
+
Any download steps should be visibly documented, and users are encouraged to take that step
|
| 74 |
+
once per repository checkout. An example (not currently in use -- that's another story) is found in
|
| 75 |
+
[riscv_prep.sh](build-tools/riscv_prep.sh), which downloads source files needed to build
|
| 76 |
+
a riscv toolchain (binutils, gcc, newlib), and is used in building our CI Docker image.
|
| 77 |
+
|
| 78 |
+
Please do NOT check-in machine generated code. If unavoidable, document it explicitly,
|
| 79 |
+
and give instructions for how to reproduce.
|
| 80 |
+
|
| 81 |
+
Understanding that the choice of a programming language depends on the task at hand:
|
| 82 |
+
Currently, synthesizable code is written in Verilog, machine-generated Verilog
|
| 83 |
+
typically comes from Python, test benches that are too complex for Verilog resort to Python,
|
| 84 |
+
and network runtime support is in Python, C, or C++.
|
| 85 |
+
|
| 86 |
+
Standard implementations and standard libraries are preferred for obvious reasons.
|
| 87 |
+
|
| 88 |
+
Automatic generation of documentation is a topic of current discussion. Suggestions welcome!
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
## Makefiles
|
| 92 |
+
|
| 93 |
+
We have an [explanation](build-tools/makefile.md) about how
|
| 94 |
+
our existing Makefiles are put together.
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
## Reproducible builds
|
| 98 |
+
|
| 99 |
+
All constructed files (sometimes called artifacts) should be reproducible.
|
| 100 |
+
See [reproducible-builds.org](https://reproducible-builds.org). This includes pretty much any machine-generated file.
|
| 101 |
+
|
| 102 |
+
Purposefully embedded "built-on" date stamps are deprecated; use
|
| 103 |
+
a git commit ID (or similar) instead.
|
| 104 |
+
|
| 105 |
+
PDF and object files often take extra effort to make reproducible.
|
| 106 |
+
|
| 107 |
+
FPGA bitfiles are not typically shown to be reproducible, but Xilinx
|
| 108 |
+
[acknowledges](https://adaptivesupport.amd.com/s/article/61599?language=en_US) that is a
|
| 109 |
+
reasonable goal (they call it "repeatable").
|
| 110 |
+
Our toolchain has demonstrated this working in at least couple of cases.
|
| 111 |
+
|
| 112 |
+
## Readability
|
| 113 |
+
|
| 114 |
+
Readability is a key goal for shared software. Lowering the barrier of entry for
|
| 115 |
+
a newcomer enables the codebase to flourish. This can be easily achieved by adhering
|
| 116 |
+
to commonly accepted best practices. Although, it may be impractical to adhere to
|
| 117 |
+
every single best practice: reading guidelines, reviewing each others code, and
|
| 118 |
+
having healthy discussions can tremendously improve the standard of software.
|
| 119 |
+
|
| 120 |
+
We're not the first group to deal with this topic. The following are
|
| 121 |
+
useful resources:
|
| 122 |
+
|
| 123 |
+
1. [Linux kernel coding style guide](https://www.kernel.org/doc/html/v4.10/process/coding-style.html) many of the concepts it discusses have general applicability.
|
| 124 |
+
2. [Google python guide](https://google.github.io/styleguide/pyguide.html) and [PEP8](https://www.python.org/dev/peps/pep-0008/)
|
| 125 |
+
3. [GNU Coding Standards: Makefile Conventions](https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html)
|
| 126 |
+
|
| 127 |
+
Please spell-check your code, comments, and documentation.
|
| 128 |
+
|
| 129 |
+
### A few rules of thumb
|
| 130 |
+
|
| 131 |
+
#### Naming
|
| 132 |
+
(This includes traditional function and variable names in compiled languages
|
| 133 |
+
like C, as wall as the various user-created names in Python, and wires,
|
| 134 |
+
regs, and module names in Verilog)
|
| 135 |
+
|
| 136 |
+
In most use cases and languages, please avoid CamelCase. You can resort to
|
| 137 |
+
snake_case instead to enhance readability of long names.
|
| 138 |
+
|
| 139 |
+
See Linux coding style "4) Naming". Pay attention to the namespace.
|
| 140 |
+
Use names that are easy to read and type, and that are not too hard to
|
| 141 |
+
grep for.
|
| 142 |
+
|
| 143 |
+
If you can reuse an existing name, for instance in Verilog using
|
| 144 |
+
the same name for a reg and the port name of a module that receives
|
| 145 |
+
that value, please do so. Creating new and slightly different names
|
| 146 |
+
for the same thing is a wasteful cognitive load.
|
| 147 |
+
|
| 148 |
+
#### Whitespace
|
| 149 |
+
|
| 150 |
+
Readability is the goal, and specialized techniques to gain readability
|
| 151 |
+
(like vertical alignment of parallel semantics) is allowed and even encouraged.
|
| 152 |
+
|
| 153 |
+
Trailing whitespace is pure useless entropy.
|
| 154 |
+
|
| 155 |
+
Unix-style line breaks, ASCII 0x0a.
|
| 156 |
+
|
| 157 |
+
No other control characters besides 0x0a (LF) and 0x09 (HT) in text/source files.
|
| 158 |
+
|
| 159 |
+
See comments above concerning binary files.
|
| 160 |
+
|
| 161 |
+
Tabs should not be used in any place other than the beginning of a line; doing so
|
| 162 |
+
invites "tab damage". OTOH, using tabs consistently at the beginning of lines
|
| 163 |
+
to represent logical indentation level has advantages; people's setting of tab
|
| 164 |
+
width can systematically and locally adjust the visual indentation level. Just
|
| 165 |
+
like Wikipedia's English vs. American spelling policy, don't gratuitously
|
| 166 |
+
change the tab vs. spaces convention of a file. See also
|
| 167 |
+
[Silicon Valley - S03E06 - Tabs versus Spaces](https://www.youtube.com/watch?v=cowtgmZuai0) (2:01).
|
| 168 |
+
|
| 169 |
+
Special case for python files:
|
| 170 |
+
No tabs, per [PEP8](https://www.python.org/dev/peps/pep-0008/)
|
| 171 |
+
|
| 172 |
+
Special case for Makefiles:
|
| 173 |
+
Semantic tabs
|
| 174 |
+
|
| 175 |
+
Special case for Xcircuit PostScript files:
|
| 176 |
+
See [hack_xcirc](build-tools/hack_xcirc); consider creating and submitting a patch to
|
| 177 |
+
avoid this in the distant future.
|
| 178 |
+
|
| 179 |
+
### Verilog
|
| 180 |
+
|
| 181 |
+
#### Of syntax
|
| 182 |
+
Verilog files should always start with a human-readable description of
|
| 183 |
+
its function. Adding a template giving name, version, and author is
|
| 184 |
+
discouraged; that's what we have version control for.
|
| 185 |
+
|
| 186 |
+
Use ANSI-C style port naming, as introduced in Verilog-2001.
|
| 187 |
+
Suggest a high proportion of comments connected with the port definitions.
|
| 188 |
+
|
| 189 |
+
Pay extra attention to module names, that are global in Verilog,
|
| 190 |
+
see "Universal considerations for names" above.
|
| 191 |
+
|
| 192 |
+
Pay extra attention to "8) Commenting" in Linux kernel style guide.
|
| 193 |
+
|
| 194 |
+
Verilog include files should use ".vh" as the name suffix.
|
| 195 |
+
|
| 196 |
+
Suggest, but do not mandate, tabs for logical indentation level, see above.
|
| 197 |
+
|
| 198 |
+
Verilog modules tend to be longer on average than C functions. This is partially
|
| 199 |
+
an unfortunate consequence of the limitations of Verilog and the overhead involved
|
| 200 |
+
in constructing a new layer/module. That is no excuse for pathologically long
|
| 201 |
+
and complicated modules, that egregiously violate Linux style guide section
|
| 202 |
+
"6) Functions". Please find ways to break up and/or autogenerate those modules.
|
| 203 |
+
|
| 204 |
+
#### Of semantics
|
| 205 |
+
|
| 206 |
+
Most of our effort should be focused on portable synthesizable Verilog modules
|
| 207 |
+
and their testing. FPGA-specific instantiations (e.g., clock management and
|
| 208 |
+
MGTs) should be separated from our functional code. Too-tight a connection
|
| 209 |
+
between them gets in the way of testing, since the Xilinx-supplied models are
|
| 210 |
+
non-redistributable and sometimes encrypted.
|
| 211 |
+
|
| 212 |
+
Portable synthesizable code should be written in a way that makes the hardware
|
| 213 |
+
representation clear to both humans and the synthesizer. All logic, flip-flops,
|
| 214 |
+
multipliers, and RAM should be inferred.
|
| 215 |
+
|
| 216 |
+
Most of our code is intended to run at relatively high clock rates. Even
|
| 217 |
+
modules that don't actually need high throughput are often put in a clock
|
| 218 |
+
domain shared with high-throughput logic. This consideration necessitates
|
| 219 |
+
strongly pipelined logic.
|
| 220 |
+
|
| 221 |
+
### Coding and style guidelines
|
| 222 |
+
|
| 223 |
+
In addition to the general recommendations above, we strive for a uniform
|
| 224 |
+
Verilog coding style that emphasizes readability, reduces systematic errors and promotes
|
| 225 |
+
code re-use. The [RTL Guidelines](guidelines/rtl_guidelines.md) document, which is itself
|
| 226 |
+
open to improvements and suggestions, attempts to formalize this process in the
|
| 227 |
+
form of coding and style guidelines that apply to some of the most common facets of RTL coding.
|
| 228 |
+
|
| 229 |
+
### Python
|
| 230 |
+
|
| 231 |
+
We want all python files compatible with python2 and python3.
|
| 232 |
+
Some legacy code can be tolerated as python2 only.
|
| 233 |
+
Some new code can be tolerated as python3 only.
|
| 234 |
+
|
| 235 |
+
A quick book for understanding patterns and Python in general: https://effectivepython.com/
|
| 236 |
+
|
| 237 |
+
## Testing
|
| 238 |
+
|
| 239 |
+
Ideally all code will be paired with a regression test that fully exercises
|
| 240 |
+
its functionality, maybe even cross-checked with a code coverage tool.
|
| 241 |
+
The more complex the function, the more important are such tests.
|
| 242 |
+
|
| 243 |
+
In general, file foo.v should define module foo, and have an associated
|
| 244 |
+
testbench in file foo_tb.v (which defines module foo_tb). There will be
|
| 245 |
+
exceptions to this rule. It's OK for other modules to be defined in
|
| 246 |
+
file foo.v, if they will never be instantiated by by any other code.
|
| 247 |
+
If possible, the testbench will give foo a thorough exercise, and print
|
| 248 |
+
PASS only if everything checks out. More complex tests may involve
|
| 249 |
+
helper code in e.g., python, that will determine if the module is performing
|
| 250 |
+
as expected. In all cases, the regression tests will be automated by
|
| 251 |
+
a Makefile rule called foo_check.
|
BerkeleyLab_Bedrock/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Copyright Notice and License Agreement
|
| 2 |
+
|
| 3 |
+
"Bedrock v1.0" Copyright (c) 2019, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
|
| 4 |
+
|
| 5 |
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
(1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
| 8 |
+
|
| 9 |
+
(2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
| 10 |
+
|
| 11 |
+
(3) Neither the name of the University of California, Lawrence Berkeley National Laboratory, U.S. Dept. of Energy, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 14 |
+
|
| 15 |
+
You are under no obligation whatsoever to provide any bug fixes, patches, or upgrades to the features, functionality or performance of the source code ("Enhancements") to anyone; however, if you choose to make your Enhancements available either publicly, or directly to Lawrence Berkeley National Laboratory, without imposing a separate written license agreement for such Enhancements, then you hereby grant the following license: a non-exclusive, royalty-free perpetual license to install, use, modify, prepare derivative works, incorporate into other computer software, distribute, and sublicense such enhancements or derivative works thereof, in binary and source code form.
|
| 16 |
+
|
| 17 |
+
NOTICE. This Software was developed under funding from the U.S. Department of Energy and the U.S. Government consequently retains certain rights. As such, the U.S. Government has been granted for itself and others acting on its behalf a paid-up, non-exclusive, irrevocable, worldwide license in the Software to reproduce, distribute copies to the public, prepare derivative works, and perform publicly and display publicly, and to permit others to do so.
|
| 18 |
+
|
| 19 |
+
If you have questions about your rights to use or distribute this software, please contact Berkeley Lab's Intellectual Property Office at: IPO@lbl.gov.
|
| 20 |
+
|
| 21 |
+
************************************************************************************
|
BerkeleyLab_Bedrock/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Overview
|
| 2 |
+
========
|
| 3 |
+
|
| 4 |
+
Bedrock generated documentation: https://berkeleylab.github.io/Bedrock/
|
| 5 |
+
|
| 6 |
+
[Bedrock](https://gitlab.lbl.gov/hdl-libraries/bedrock) is largely an accumulation
|
| 7 |
+
of Verilog codebase written over the past several years at LBNL. It contains
|
| 8 |
+
platform-independent Verilog, and whatever it takes to get it onto FPGA platforms like Xilinx etc.
|
| 9 |
+
|
| 10 |
+
It is currently a conglomerate of code broken into the following subdirectories:
|
| 11 |
+
|
| 12 |
+
* [dsp](dsp): Various Digital Signal Processing algorithms
|
| 13 |
+
implemented in platform-independent (portable) Verilog, and their test benches;
|
| 14 |
+
modules include DDS, Down-conversion, Up-conversion, CIC Filters,
|
| 15 |
+
Low-Pass filters, High-Pass filters, Mixers
|
| 16 |
+
* [cordic](cordic): A self contained Verilog implementation of a
|
| 17 |
+
[CORDIC](https://en.wikipedia.org/wiki/CORDIC);
|
| 18 |
+
includes several operating modes that can be selected at build-time or run-time
|
| 19 |
+
* rtsim: Real-Time simulation of various components of an RF system like a
|
| 20 |
+
resonant cavity, its Electrical and Mechanical modes, ADCs, Cables, Piezos etc.
|
| 21 |
+
* cmoc: Verilog implementation of an RF controller, that connects to either a
|
| 22 |
+
real world ADCs or simulated components within rtsim
|
| 23 |
+
* [badger](badger): A real-time Ethernet/IP/UDP packet responder core in fabric
|
| 24 |
+
* fpga_family: Several FPGA specific constraint files and hooks for vendor-specific features
|
| 25 |
+
* [localbus](localbus): Documentation and features related to the on-chip localbus that is widely used within bedrock
|
| 26 |
+
* board_support: Several board specific pin mapping related files
|
| 27 |
+
* projects: Instantiated projects that build and synthesize bit files that go on
|
| 28 |
+
FPGAs sitting on various boards that talk various platforms
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
A few comments regarding the codebase
|
| 32 |
+
|
| 33 |
+
1. All software is set up to easily run on *nix systems.
|
| 34 |
+
2. Currently everything is [built using GNU Make](build-tools/makefile.md).
|
| 35 |
+
We are on an active lookout for other methods, if they're actually better for us.
|
| 36 |
+
3. iverilog is used for simulation. We are slowly starting to use [Verilator](https://www.veripool.org/verilator/) as well
|
| 37 |
+
(see badger)
|
| 38 |
+
4. Xilinx tools are used for synthesis, and starting to support [YoSys](https://yosyshq.net/yosys/) (again see badger)
|
| 39 |
+
5. This repository is connected to Gitlab CI. All simulation based tests run
|
| 40 |
+
automatically upon every commit on the continuous integration server. This helps
|
| 41 |
+
us move faster (without breaking things). A helpful subset of those tests
|
| 42 |
+
can be run locally on your workstation via [selftest.sh](selftest.sh).
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Graphical x Batch mode
|
| 46 |
+
======================
|
| 47 |
+
|
| 48 |
+
Bedrock is structured in such a way to make use of traditional *nix
|
| 49 |
+
tools, such as `make` and `grep`, shell and python scripts from the
|
| 50 |
+
command-line. This makes it easy to automate the build process, customize
|
| 51 |
+
steps, and gives flexibility to add hooks for generating code, stubs,
|
| 52 |
+
definitions and much more.
|
| 53 |
+
|
| 54 |
+
However, there are valid cases for using a graphical, interactive
|
| 55 |
+
interface such as: analyzing elaborated, synthesized or implemented
|
| 56 |
+
design schematic; adding/removing placement constraints;
|
| 57 |
+
customizing a block design; customizing an IP core from a vendor.
|
| 58 |
+
|
| 59 |
+
Bedrock keeps all the vendor-specific generated files in a _<VENDOR_NAME>
|
| 60 |
+
directory in the synthesis directory. So, for instance, when synthesizing
|
| 61 |
+
a design for `Xilinx`, Bedrock scripts will create a directory called
|
| 62 |
+
`_xilinx` with the unmodified vendor files within.
|
| 63 |
+
|
| 64 |
+
In this way, after the vendor project file is created (see the
|
| 65 |
+
[build-tools discussion](build-tools/makefile.md) for details),
|
| 66 |
+
one can simply invoke the vendor tool manually with the project
|
| 67 |
+
file name as the argument.
|
| 68 |
+
|
| 69 |
+
For instance, if using Vivado, one can use the following command
|
| 70 |
+
to open a project in Graphical mode:
|
| 71 |
+
|
| 72 |
+
```bash
|
| 73 |
+
vivado <PROJECT_DIRECTORY>/_xilinx/<TOP_LEVEL_DESIGN_NAME>/<TOP_LEVEL_DESIGN_NAME>.xpr
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
in which `<PROJECT_DIRECTORY>` is the directory in which you invoked
|
| 77 |
+
`make` and `<TOP_LEVEL_DESIGN_NAME>` is the bitstream name without the
|
| 78 |
+
`.bit` extension.
|
| 79 |
+
|
| 80 |
+
Dependencies
|
| 81 |
+
============
|
| 82 |
+
|
| 83 |
+
Required:
|
| 84 |
+
|
| 85 |
+
* GNU Make
|
| 86 |
+
* iverilog
|
| 87 |
+
* Python
|
| 88 |
+
|
| 89 |
+
Recommended:
|
| 90 |
+
|
| 91 |
+
* GTKWave
|
| 92 |
+
* Xilinx Vivado
|
| 93 |
+
* Verilator
|
| 94 |
+
* YoSys
|
| 95 |
+
|
| 96 |
+
Full list: see [dependencies.txt](dependencies.txt) and [Dockerfile](Dockerfile.bedrock_testing_base_trixie).
|
| 97 |
+
|
| 98 |
+
On contributing
|
| 99 |
+
===============
|
| 100 |
+
See our first take [here](CONTRIBUTING.md)
|
| 101 |
+
|
| 102 |
+
************************************************************************************
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
### Copyright Notice and License Agreement
|
| 106 |
+
|
| 107 |
+
See [LICENSE](LICENSE.md).
|
BerkeleyLab_Bedrock/badger/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Packet Badger
|
| 2 |
+
|
| 3 |
+
## Introduction
|
| 4 |
+
|
| 5 |
+
Packet Badger is a digital logic design, implemented on an FPGA, that
|
| 6 |
+
digs through Ethernet packets to construct a response. Its intended
|
| 7 |
+
application is to let workstations and servers communicate with FPGA-based
|
| 8 |
+
instruments over UDP. On its own, it provides ARP, ICMP echo, and UDP echo
|
| 9 |
+
services. It has a (documented and tested) interface to add additional
|
| 10 |
+
UDP services that provide the application-useful data flow.
|
| 11 |
+
|
| 12 |
+
Packet Badger attaches to Ethernet using the GMII standard. Adapter layers
|
| 13 |
+
inside the FPGA can let it connect to GMII, RGMII, SGMII, or MGT PHY hardware.
|
| 14 |
+
Mechanisms are provided to attach a software-based simulation of Packet Badger
|
| 15 |
+
to the computer's TUN/TAP subsystem (requires root access for setup),
|
| 16 |
+
or single clients to a UDP socket, permitting development of client software
|
| 17 |
+
and HDL without depending on the target hardware.
|
| 18 |
+
|
| 19 |
+
Packet Badger is written in portable, synthesizable Verilog. When targeting
|
| 20 |
+
Xilinx 7-series chips, it occupies about 1000 LUTs and 1 RAMB18.
|
| 21 |
+
|
| 22 |
+
Packet Badger is designed to only respond promptly to packets, never initiate
|
| 23 |
+
traffic. It is tuned for plug-in modules (one per UDP service port) that can
|
| 24 |
+
respond in a fixed number (parameterized) of clock cycles latency. Examples
|
| 25 |
+
are given for such modules that:
|
| 26 |
+
|
| 27 |
+
* Gateway to an on-chip local bus (protocol [documentation](mem_gate.md))
|
| 28 |
+
* Give read/write access to an SPI Flash memory
|
| 29 |
+
|
| 30 |
+
Unlike logic designs that use a soft core to implement Ethernet/IP protocols,
|
| 31 |
+
it is capable of full-rate gigabit-per-second data transfer, and has a
|
| 32 |
+
relatively small footprint in the FPGA fabric and memory.
|
| 33 |
+
|
| 34 |
+
This design roughly parallels an earlier LBNL Ethernet fabric design
|
| 35 |
+
(PSPEPS), but with architectural bugs fixed. If the Ethernet physical
|
| 36 |
+
link stays up, it will never drop a packet.
|
| 37 |
+
|
| 38 |
+
The architecture permits adding a MAC for a soft-core CPU, that could be
|
| 39 |
+
useful for low-bandwidth setup functions like DHCP or SCPI. An initial
|
| 40 |
+
implementation is included.
|
| 41 |
+
|
| 42 |
+
The author asserts that its architecture will permit addition of strong
|
| 43 |
+
authentication to each packet, without adding (much) overhead in latency,
|
| 44 |
+
throughput, or hardware resources. Efforts to demonstrate that are still
|
| 45 |
+
in a prototyping stage, and are not included here.
|
| 46 |
+
|
| 47 |
+
Only synthesizable code, programs (and their data) to generate synthesizable
|
| 48 |
+
code, and documentation are here in the base directory. Files that implement
|
| 49 |
+
the extensive self-test capability, including test builds for hardware, are
|
| 50 |
+
squirreled away in the tests/ directory. Projects that instantiate this
|
| 51 |
+
code are expected to accomplish the build step by including rules.mk.
|
| 52 |
+
|
| 53 |
+
## Block Diagram
|
| 54 |
+
|
| 55 |
+

|
| 56 |
+
|
| 57 |
+
## Self-tests
|
| 58 |
+
|
| 59 |
+
An extensive set of self-tests and demonstrations are programmed up in
|
| 60 |
+
the tests subdirectory. These range from simple exercises for the
|
| 61 |
+
input packet scanner to running a TFTP server that uses the MAC feature.
|
| 62 |
+
Some of these tests attach the simulated logic to the host network.
|
| 63 |
+
|
| 64 |
+
The self-tests are run as part of a Continuous Integration (CI) process.
|
| 65 |
+
You can also run them on your workstation with a simple "cd tests; make".
|
| 66 |
+
|
| 67 |
+
## Functionality
|
| 68 |
+
|
| 69 |
+
Input packets are checked according to the following.
|
| 70 |
+
Failures are not reported, just dropped.
|
| 71 |
+
|
| 72 |
+
All packets:
|
| 73 |
+
|
| 74 |
+
* Source MAC is unicast, not multicast
|
| 75 |
+
* CRC32 OK
|
| 76 |
+
* Total GMII frame length (including Ethernet header and CRC32) <= 1536
|
| 77 |
+
* Minimum frame length _not_ checked
|
| 78 |
+
|
| 79 |
+
ARP request:
|
| 80 |
+
|
| 81 |
+
* EtherType 0x0806
|
| 82 |
+
* Hardware address space 1 (Ethernet)
|
| 83 |
+
* Protocol address space 0x0800 (Ethernet/IP)
|
| 84 |
+
* 6-byte hardware addresses, 4-byte protocol addresses
|
| 85 |
+
* Opcode 1 (request)
|
| 86 |
+
* _No_ checks on embedded source IP or MAC
|
| 87 |
+
* Dest IP matches our configuration
|
| 88 |
+
* _No_ checks on embedded dest MAC
|
| 89 |
+
* _No_ checks on Ethernet header dest MAC (normally broadcast)
|
| 90 |
+
|
| 91 |
+
IP:
|
| 92 |
+
|
| 93 |
+
* Dest MAC matches our configuration
|
| 94 |
+
* EtherType 0x0800
|
| 95 |
+
* IPv4
|
| 96 |
+
* No options
|
| 97 |
+
* IP total length fits within its GMII frame
|
| 98 |
+
* No fragmentation
|
| 99 |
+
* Non-zero TTL
|
| 100 |
+
* IP header checksum OK
|
| 101 |
+
* _No_ checks on source IP address
|
| 102 |
+
* Dest IP matches our configuration
|
| 103 |
+
|
| 104 |
+
ICMP echo request (depends on IP):
|
| 105 |
+
|
| 106 |
+
* IP Protocol 1
|
| 107 |
+
* ICMP type 8, code 0
|
| 108 |
+
* ICMP checksum OK
|
| 109 |
+
|
| 110 |
+
UDP (depends on IP):
|
| 111 |
+
|
| 112 |
+
* IP Protocol 17
|
| 113 |
+
* Source port >= 1024
|
| 114 |
+
* Dest port matches one of the clients (but not zero)
|
| 115 |
+
* Length fits within IP packet
|
| 116 |
+
* UDP checksum _not_ checked
|
| 117 |
+
|
| 118 |
+
If a reply is sent, it _always_ has its destination MAC transcribed
|
| 119 |
+
from the requesting packet's source MAC. Likewise, the destination IP
|
| 120 |
+
is transcribed from the source IP (although this means different things
|
| 121 |
+
for ARP and IP), and the UDP destination port is transcribed from the
|
| 122 |
+
source port.
|
| 123 |
+
|
| 124 |
+
Up to eight on-chip plug-in clients (UDP ports) are currently supported,
|
| 125 |
+
and their default ports are numbered sequentially starting at 801.
|
| 126 |
+
This can be overridden at build time with Verilog parameters, or
|
| 127 |
+
at run time with a local configuration bus.
|
| 128 |
+
|
| 129 |
+
It is strongly recommended that UDP destination port numbers get configured
|
| 130 |
+
to be < 1024, to resist UDP loops. Somehow this well-known (CA-1996-01:
|
| 131 |
+
UDP Port Denial-of-Service Attack) possibility was rediscovered
|
| 132 |
+
in 2024, and assigned CVE-2024-2169: Loop DoS. Separating "services"
|
| 133 |
+
(ports < 1024) from "clients" (ports > 1023) is Preventive measure 2
|
| 134 |
+
listed in the Loop DoS advisory.
|
| 135 |
+
|
| 136 |
+
## Example "live" test run
|
| 137 |
+
|
| 138 |
+
Demonstrating both Packet Badger functionality, and the test framework's
|
| 139 |
+
ability to attach the simulation to the host's Ethernet subsystem.
|
| 140 |
+
|
| 141 |
+
Your development machine needs to provide a traditional unix-y environment,
|
| 142 |
+
e.g., make, cc, python, awk, cmp. Also some version of [Icarus Verilog](https://steveicarus.github.io/iverilog/); see [status.md](status.md) for more details.
|
| 143 |
+
|
| 144 |
+
In one shell session (Linux terminal), try:
|
| 145 |
+
|
| 146 |
+
cd tests
|
| 147 |
+
sudo tunctl -u $USER && sudo ifconfig tap0 192.168.7.1 up
|
| 148 |
+
make tap_start
|
| 149 |
+
|
| 150 |
+
In another terminal, try the following to pull contents from `fake_config_romx.v`
|
| 151 |
+
through `mem_gateway.v` at IP address `192.168.7.4`, localbus UDP port 803:
|
| 152 |
+
|
| 153 |
+
printf "sillyoneT\x1\x0\x0yyyyT\x1\x0\x1yyyyT\x1\x0\x2yyyyT\x1\x0\x3yyyy" | nc -q 1 -u 192.168.7.4 803 | hexdump -v -e '8/1 "%2.2x " " "' -e '8/1 "%_p" "\n"'
|
| 154 |
+
|
| 155 |
+
Expected result:
|
| 156 |
+
|
| 157 |
+
73 69 6c 6c 79 6f 6e 65 sillyone
|
| 158 |
+
54 01 00 00 00 00 80 0a T.......
|
| 159 |
+
54 01 00 01 00 00 73 34 T.....s4
|
| 160 |
+
54 01 00 02 00 00 b9 48 T......H
|
| 161 |
+
54 01 00 03 00 00 d2 76 T......v
|
| 162 |
+
|
| 163 |
+
You can now interrupt (control-C) the simulation. That process should
|
| 164 |
+
have left behind a rtefi_pipe.vcd file that can be viewed with gtkwave;
|
| 165 |
+
a pre-configured gtkwave pane can be brought up with "make rtefi_pipe_view".
|
| 166 |
+
|
| 167 |
+
## Attachment of clients:
|
| 168 |
+

|
| 169 |
+
|
| 170 |
+
Each client handles one UDP port.
|
| 171 |
+
Up to eight clients can be attached to a Packet Badger instance.
|
| 172 |
+
|
| 173 |
+
## Other documentation
|
| 174 |
+
|
| 175 |
+
* Design notes: [rtefi_notes.txt](rtefi_notes.txt)
|
| 176 |
+
* Memory addressing figure: [memory access diagram](doc/memory.svg)
|
| 177 |
+
* Data path in construct.v: [data path diagram](doc/tx_path.svg)
|
| 178 |
+
* SPI Boot Flash programming support: [flash.md](flash.md)
|
| 179 |
+
* Status: [status.md](status.md)
|
BerkeleyLab_Bedrock/badger/base_rx_mac.v
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Baseline/provisional/experimental Rx MAC,
|
| 2 |
+
// ties to functionality in pbuf_writer.v
|
| 3 |
+
//
|
| 4 |
+
// 11-bit host_raddr for dpram addressing.
|
| 5 |
+
// Packet memory appears to host as 16 bits wide,
|
| 6 |
+
// so 4 kBytes overall.
|
| 7 |
+
module base_rx_mac (
|
| 8 |
+
// Host side of Rx MAC memory
|
| 9 |
+
input host_clk,
|
| 10 |
+
input [10:0] host_raddr,
|
| 11 |
+
output reg [15:0] host_rdata,
|
| 12 |
+
// port to Rx MAC memory
|
| 13 |
+
input rx_clk,
|
| 14 |
+
input [7:0] rx_mac_d,
|
| 15 |
+
input [11:0] rx_mac_a,
|
| 16 |
+
input rx_mac_wen,
|
| 17 |
+
// port to Rx MAC packet selector
|
| 18 |
+
output rx_mac_accept,
|
| 19 |
+
input [7:0] rx_mac_status_d,
|
| 20 |
+
input rx_mac_status_s
|
| 21 |
+
);
|
| 22 |
+
initial host_rdata=0;
|
| 23 |
+
|
| 24 |
+
// Dual-port RAM
|
| 25 |
+
localparam aw=11;
|
| 26 |
+
reg [7:0] pack_mem_l[0:(1<<aw)-1];
|
| 27 |
+
reg [7:0] pack_mem_h[0:(1<<aw)-1];
|
| 28 |
+
// Write from Ethernet, 8-bit port and therefore aw+1 address bits coming in
|
| 29 |
+
wire a_lsb = rx_mac_a[0];
|
| 30 |
+
wire [aw-1:0] a_msb = rx_mac_a[aw:1];
|
| 31 |
+
always @(posedge rx_clk) if (rx_mac_wen) begin
|
| 32 |
+
if (a_lsb) pack_mem_l[a_msb] <= rx_mac_d;
|
| 33 |
+
else pack_mem_h[a_msb] <= rx_mac_d;
|
| 34 |
+
end
|
| 35 |
+
// Read from host
|
| 36 |
+
wire [aw-1:0] raddr = host_raddr;
|
| 37 |
+
always @(posedge host_clk) host_rdata <= {pack_mem_h[raddr], pack_mem_l[raddr]};
|
| 38 |
+
|
| 39 |
+
// Accept valid IP packets addressed to us, that won't be handled by fabric.
|
| 40 |
+
// See comments regarding status_vec in scanner.v.
|
| 41 |
+
reg rx_mac_accept_r=0;
|
| 42 |
+
always @(posedge rx_clk) if (rx_mac_status_s)
|
| 43 |
+
rx_mac_accept_r <= rx_mac_status_d[4:0] == 5'b11100;
|
| 44 |
+
assign rx_mac_accept = rx_mac_accept_r;
|
| 45 |
+
|
| 46 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/collect_clients.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Parses one Verilog file per client, and creates rtefi_preblob.vh
|
| 2 |
+
# that will define the instantiation and I/O port routing of the final
|
| 3 |
+
# rtefi_blob.v.
|
| 4 |
+
#
|
| 5 |
+
# The fundamental bug with this program is that it's
|
| 6 |
+
# based on text patterns, not semantics.
|
| 7 |
+
# At least it doesn't use magic comments!
|
| 8 |
+
from sys import argv
|
| 9 |
+
import re
|
| 10 |
+
xlist = []
|
| 11 |
+
params = []
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def handle_port(plist, x2list, ptype, name, ix):
|
| 15 |
+
special_list = {'clk': 1, 'len_c': 1, 'idata': 1,
|
| 16 |
+
'raw_l': 1, 'raw_s': 1, 'odata': 1}
|
| 17 |
+
ename = name
|
| 18 |
+
if name not in special_list:
|
| 19 |
+
ename = "p%d_%s" % (ix, name)
|
| 20 |
+
# print("adding to x2list: %s, %s" % (ptype, ename))
|
| 21 |
+
x2list += [(ptype, ename)]
|
| 22 |
+
if name == "raw_l" or name == "raw_s":
|
| 23 |
+
ename = "%s[%d]" % (name, ix-1)
|
| 24 |
+
if name == "odata":
|
| 25 |
+
ename = "%s_p%d" % (name, ix)
|
| 26 |
+
plist += [".%s(%s)" % (name, ename)]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def map_params(ix, spec, params):
|
| 30 |
+
# print("// map_params(%d, %s ..)" % (ix, spec))
|
| 31 |
+
prefix = "p%d_" % ix
|
| 32 |
+
|
| 33 |
+
# Define a function to be used as repl argument to re.sub()
|
| 34 |
+
# Ideally we'd not try to process the leading input / output string
|
| 35 |
+
def param_replace(matchobj):
|
| 36 |
+
m = matchobj.group(0)
|
| 37 |
+
# print(m)
|
| 38 |
+
return prefix+m if m in params else m
|
| 39 |
+
ss = re.sub(r'([a-zA-Z]\w*)', param_replace, spec)
|
| 40 |
+
# print("// After: %s" % ss)
|
| 41 |
+
return ss
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# regexps for I/O ports, with and without a specified width
|
| 45 |
+
# It would be cool if we could also propagate comments
|
| 46 |
+
# associated with ports and parameters.
|
| 47 |
+
PORT_N = r'^\s*,?(input|output|inout)\s+(signed)?\s*(\[[^]]+\])\s*(\w+)'
|
| 48 |
+
PORT_0 = r'^\s*,?(input|output|inout)\s+(signed)?\s*(\w+)'
|
| 49 |
+
PARAM = r'^\s*,?parameter\s+(\w+)\s*=\s*(\d+)'
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def file_grab(fname, ix):
|
| 53 |
+
plist = []
|
| 54 |
+
x2list = []
|
| 55 |
+
global xlist
|
| 56 |
+
global params
|
| 57 |
+
param_map = []
|
| 58 |
+
param_set = [".n_lat(n_lat)"]
|
| 59 |
+
with open(fname, 'r') as f:
|
| 60 |
+
for li in f.read().split('\n'):
|
| 61 |
+
if li == "":
|
| 62 |
+
continue
|
| 63 |
+
# print(l)
|
| 64 |
+
m = re.search(PORT_N, li)
|
| 65 |
+
if m:
|
| 66 |
+
ll = [m.group(jx) for jx in [1, 2, 3]]
|
| 67 |
+
p = " ".join([x if x is not None else "" for x in ll])
|
| 68 |
+
handle_port(plist, x2list, p, m.group(4), ix)
|
| 69 |
+
m = re.search(PORT_0, li)
|
| 70 |
+
if m:
|
| 71 |
+
ll = [m.group(jx) for jx in [1, 2]]
|
| 72 |
+
p = " ".join([x if x is not None else "" for x in ll])
|
| 73 |
+
handle_port(plist, x2list, p, m.group(3), ix)
|
| 74 |
+
m = re.search(PARAM, li)
|
| 75 |
+
if m and m.group(1) != "n_lat":
|
| 76 |
+
pn = m.group(1)
|
| 77 |
+
pv = m.group(2)
|
| 78 |
+
params += ["\tparameter p%d_%s = %s," % (ix, pn, pv)]
|
| 79 |
+
param_set += [".%s(p%d_%s)" % (pn, ix, pn)]
|
| 80 |
+
param_map += [pn]
|
| 81 |
+
for p_spec, p_name in x2list:
|
| 82 |
+
p_spec2 = map_params(ix, p_spec, param_map)
|
| 83 |
+
xlist += ['\t%s %s,' % (p_spec2, p_name)]
|
| 84 |
+
# Generate the module name from the file name;
|
| 85 |
+
# directories and .v suffixes aren't kept.
|
| 86 |
+
# print("// Finalizing %s" % fname)
|
| 87 |
+
# print(plist)
|
| 88 |
+
mod_name = fname.split('/')[-1]
|
| 89 |
+
mod_name = mod_name.split('.')[0]
|
| 90 |
+
param_sets = ", ".join(param_set)
|
| 91 |
+
ss = "%s #(%s) p%d_client(" % (mod_name, param_sets, ix)
|
| 92 |
+
ss += ", ".join(plist)
|
| 93 |
+
ss += ");"
|
| 94 |
+
return ss
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
ss = []
|
| 98 |
+
n_used = len(argv)-1
|
| 99 |
+
print("// This Verilog include file was machine-generated by {}".format(__file__))
|
| 100 |
+
for ix, fname in enumerate(argv[1:]):
|
| 101 |
+
print("// %d %s" % (ix+1, fname))
|
| 102 |
+
ss += [file_grab(fname, ix+1)]
|
| 103 |
+
print("// filling in unused UDP ports starting at %d" % (n_used+1))
|
| 104 |
+
for ix in range(n_used+1, 8):
|
| 105 |
+
ss += ["assign odata_p%d = 8'h%2x;" % (ix, 48+ix)]
|
| 106 |
+
|
| 107 |
+
print("`define BLOB_INSTANCES \\")
|
| 108 |
+
print("\\\n".join(ss))
|
| 109 |
+
print("`define BLOB_PORTS \\")
|
| 110 |
+
print("\\\n".join(xlist))
|
| 111 |
+
print("`define BLOB_PARAMS \\")
|
| 112 |
+
print("\\\n".join(params))
|
BerkeleyLab_Bedrock/badger/construct.v
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Output packet construction
|
| 2 |
+
|
| 3 |
+
// Handles Ethernet, ARP, and IP layers, ready to hand over
|
| 4 |
+
// to the application-layer UDP content handling.
|
| 5 |
+
// The core of the data path is documented in doc/tx_path.eps,
|
| 6 |
+
// with the table generated by tx_gen.py based on
|
| 7 |
+
// tx_*_table.csv.
|
| 8 |
+
|
| 9 |
+
// Synthesized on its own, without the associated packet memory
|
| 10 |
+
// or MAC/IP config memory, it takes up about 74 LUTs.
|
| 11 |
+
|
| 12 |
+
module construct #(
|
| 13 |
+
parameter paw=11, // packet address width, 11 IRL, maybe less for simulations
|
| 14 |
+
parameter p_offset = 480 // Keep an eye on this.
|
| 15 |
+
// Has to be at least 6 for usual fp_offset of 0, but also
|
| 16 |
+
// add -min(fp_offset)+guard. The guard needs to include
|
| 17 |
+
// allowance Rx/Tx frequency offset.
|
| 18 |
+
// At the other end, p_offset + max(fp_offset) < (2048-MTU-guard)
|
| 19 |
+
) (
|
| 20 |
+
input clk, // timespec 6.8 ns
|
| 21 |
+
input [paw-1:0] gray_state,
|
| 22 |
+
// port to MAC/IP config, single-cycle latency
|
| 23 |
+
output [3:0] ip_a,
|
| 24 |
+
input [7:0] ip_d,
|
| 25 |
+
// Read port of 1 MTU DPRAM, again single-cycle latency
|
| 26 |
+
output [paw-1:0] addr,
|
| 27 |
+
input [8:0] pbuf_out,
|
| 28 |
+
// Debugging hook
|
| 29 |
+
output badge_stb,
|
| 30 |
+
output [7:0] badge_data,
|
| 31 |
+
output xdomain_fault,
|
| 32 |
+
output xcheck_fault,
|
| 33 |
+
// Output to xformer
|
| 34 |
+
output [5:0] pc,
|
| 35 |
+
output [1:0] category,
|
| 36 |
+
output [2:0] udp_sel,
|
| 37 |
+
output [7:0] eth_data_out,
|
| 38 |
+
output eth_strobe_long, // includes GMII preamble and CRC32
|
| 39 |
+
output eth_strobe_short // doesn't
|
| 40 |
+
);
|
| 41 |
+
|
| 42 |
+
// Capture state across clock domains, then convert back to binary
|
| 43 |
+
wire [paw-1:0] gray_l;
|
| 44 |
+
// Better to pull this first step up to rtefi_center?
|
| 45 |
+
reg_tech_cdc gcx[paw-1:0] (.C(clk), .I(gray_state), .O(gray_l));
|
| 46 |
+
// verilator lint_save
|
| 47 |
+
// verilator lint_off UNOPTFLAT
|
| 48 |
+
wire [paw-1:0] new_state = gray_l ^ {1'b0, new_state[paw-1:1]};
|
| 49 |
+
// verilator lint_restore
|
| 50 |
+
reg [paw-1:0] state=0;
|
| 51 |
+
always @(posedge clk) state <= new_state;
|
| 52 |
+
|
| 53 |
+
// Debugging hook
|
| 54 |
+
reg [paw-1:0] old_state=0, state_diff=0;
|
| 55 |
+
reg xdomain_fault_r=0;
|
| 56 |
+
always @(posedge clk) begin
|
| 57 |
+
old_state <= state;
|
| 58 |
+
state_diff <= state - old_state;
|
| 59 |
+
// state_diff must be 0, 1, or 2 for things to work right
|
| 60 |
+
xdomain_fault_r <= |state_diff[paw-1:2] || &state_diff[1:0];
|
| 61 |
+
end
|
| 62 |
+
assign xdomain_fault = xdomain_fault_r;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
// Construct frame pointer that tracks the one in scanner.v
|
| 66 |
+
wire packet_active;
|
| 67 |
+
wire [paw-1:0] fp;
|
| 68 |
+
`ifdef COMMON_CLOCKS
|
| 69 |
+
assign fp = state + p_offset;
|
| 70 |
+
`else
|
| 71 |
+
// cope with max 100 ppm frequency offset between input and output.
|
| 72 |
+
reg [paw-1:0] fp_r=0;
|
| 73 |
+
assign fp = packet_active ? fp_r+1 : state+p_offset;
|
| 74 |
+
always @(posedge clk) fp_r <= fp;
|
| 75 |
+
// This will be really slow. Have to pack an increment, mux, add,
|
| 76 |
+
// and RAM access into a single cycle.
|
| 77 |
+
`endif
|
| 78 |
+
// XXX Deserves a consistency check to find out if fp drifts into
|
| 79 |
+
// a danger zone relative to state.
|
| 80 |
+
|
| 81 |
+
reg [5:0] pc_r=0;
|
| 82 |
+
// SOF: Start Of Frame
|
| 83 |
+
wire pre_sof = pbuf_out[8] & ~pbuf_out[7] && (pc_r==0);
|
| 84 |
+
wire sof = pbuf_out[8] & pbuf_out[7] && (pc_r==0); // hack to get around x's in fp_offset
|
| 85 |
+
wire [7:0] pbuf_out8 = pbuf_out[7:0];
|
| 86 |
+
wire signed [5:0] fp_offset, cf_offset;
|
| 87 |
+
reg live=0;
|
| 88 |
+
assign packet_active = pre_sof | sof | live;
|
| 89 |
+
reg [10:0] pack_len_r=0;
|
| 90 |
+
wire pc_not_saturated = |(~pc_r[5:4]); // check if pc < 48
|
| 91 |
+
wire [5:0] next_pc = sof ? 2 : live ? pc_r + pc_not_saturated : 0;
|
| 92 |
+
|
| 93 |
+
// reference: status_vec = {port_p, pass_ip, pass_ethmac, crc_zero, category};
|
| 94 |
+
reg [7:0] status_vec=0;
|
| 95 |
+
assign category = status_vec[1:0];
|
| 96 |
+
assign udp_sel = status_vec[7:5];
|
| 97 |
+
reg p_strobe=0; // Reading packet content (including checksum)
|
| 98 |
+
reg o_strobe=0; // ignores checksum
|
| 99 |
+
reg sof_d=0;
|
| 100 |
+
// Would it take fewer resources to replace sof_d with (live && pc_r == 2)?
|
| 101 |
+
// Or to replace (live && pc_r==3) with sof_dd? Need to measure to find out.
|
| 102 |
+
// Could be worth breaking this up into 2 always blocks (badge and data)?
|
| 103 |
+
// Not really, since they both have to touch the "live" register.
|
| 104 |
+
always @(posedge clk) begin
|
| 105 |
+
pc_r <= next_pc;
|
| 106 |
+
sof_d <= sof;
|
| 107 |
+
if (sof) begin
|
| 108 |
+
live <= 1;
|
| 109 |
+
pack_len_r[6:0] <= pbuf_out8[6:0];
|
| 110 |
+
end
|
| 111 |
+
if (sof_d) pack_len_r[10:7] <= pbuf_out8[3:0];
|
| 112 |
+
if (live && pc_r==3) status_vec <= pbuf_out8;
|
| 113 |
+
// pc_r == 5 the badge has been read!
|
| 114 |
+
if (live && pc_r==5 && category!=0) begin o_strobe <= 1; p_strobe <= 1; end
|
| 115 |
+
if (live && pc_r==5 && category==0) begin live <= 0; pack_len_r <= 0; end
|
| 116 |
+
if (p_strobe) pack_len_r <= pack_len_r-1;
|
| 117 |
+
if (pack_len_r==5) o_strobe <= 0;
|
| 118 |
+
if (pack_len_r==1) begin p_strobe <= 0; live <= 0; end
|
| 119 |
+
end
|
| 120 |
+
|
| 121 |
+
// Debug
|
| 122 |
+
reg [2:0] sof_chain=0;
|
| 123 |
+
always @(posedge clk) sof_chain <= {sof_chain[1:0], sof};
|
| 124 |
+
assign badge_stb = sof | (|sof_chain);
|
| 125 |
+
assign badge_data = pbuf_out8;
|
| 126 |
+
|
| 127 |
+
// Look up instruction and start using it
|
| 128 |
+
wire [1:0] out, chk_in;
|
| 129 |
+
wire [7:0] template;
|
| 130 |
+
construct_tx_table prog(.a({category, pc_r}),
|
| 131 |
+
.v({out, fp_offset, cf_offset, chk_in, template}));
|
| 132 |
+
assign addr = fp + {{5{fp_offset[5]}}, fp_offset};
|
| 133 |
+
assign ip_a = pc_r + cf_offset;
|
| 134 |
+
|
| 135 |
+
// Align cycles with the one-cycle delay going through RAM
|
| 136 |
+
// (a bit wasteful, could mess with table generation instead?)
|
| 137 |
+
// Pipelining not shown in doc/tx_path.eps
|
| 138 |
+
reg [7:0] template_d=0;
|
| 139 |
+
reg [1:0] out_d=0, chk_in_d=0;
|
| 140 |
+
always @(posedge clk) begin
|
| 141 |
+
template_d <= template;
|
| 142 |
+
out_d <= out;
|
| 143 |
+
chk_in_d <= chk_in;
|
| 144 |
+
end
|
| 145 |
+
|
| 146 |
+
// Multiplexers, need to stay consistent with tx_gen.py
|
| 147 |
+
reg [7:0] d_chk=0;
|
| 148 |
+
always @(posedge clk) case (chk_in_d)
|
| 149 |
+
2'b00: d_chk <= pbuf_out8;
|
| 150 |
+
2'b01: d_chk <= ip_d;
|
| 151 |
+
2'b10: d_chk <= template_d;
|
| 152 |
+
2'b11: d_chk <= 8'd0;
|
| 153 |
+
endcase
|
| 154 |
+
wire [7:0] ip_head_chksum_data;
|
| 155 |
+
// IP header checksum calculation
|
| 156 |
+
reg chksum_zero=0, chksum_gate=0;
|
| 157 |
+
always @(posedge clk) begin
|
| 158 |
+
chksum_zero <= pc_r <= 3;
|
| 159 |
+
chksum_gate <= (chk_in_d != 2'b11) & ~chksum_zero;
|
| 160 |
+
end
|
| 161 |
+
ones_chksum ck(.clk(clk), .clear(chksum_zero), .gate(chksum_gate),
|
| 162 |
+
.din(d_chk), .sum(ip_head_chksum_data));
|
| 163 |
+
|
| 164 |
+
reg [7:0] d_out_pre=0;
|
| 165 |
+
always @(posedge clk) case (out_d)
|
| 166 |
+
2'b00: d_out_pre <= pbuf_out8;
|
| 167 |
+
2'b01: d_out_pre <= ip_d;
|
| 168 |
+
2'b10: d_out_pre <= template_d;
|
| 169 |
+
2'b11: d_out_pre <= 0;
|
| 170 |
+
endcase
|
| 171 |
+
// Last-minute insertion of IP header checksum result .. haha minute
|
| 172 |
+
reg out_d_chk_sub=0;
|
| 173 |
+
always @(posedge clk) out_d_chk_sub <= out_d == 2'b11;
|
| 174 |
+
wire [7:0] d_out = out_d_chk_sub ? ip_head_chksum_data : d_out_pre;
|
| 175 |
+
// This could create a critical speed path
|
| 176 |
+
|
| 177 |
+
// Close out timing within this module
|
| 178 |
+
reg [7:0] eth_data_out_r=0; always @(posedge clk) eth_data_out_r <= d_out;
|
| 179 |
+
reg eth_strobe_short_r=0; always @(posedge clk) eth_strobe_short_r <= o_strobe;
|
| 180 |
+
reg pack_len_nz=0; always @(posedge clk) pack_len_nz <= pack_len_r != 0;
|
| 181 |
+
reg [5:0] pc_d=0; always @(posedge clk) pc_d <= pc_r;
|
| 182 |
+
|
| 183 |
+
assign eth_data_out = eth_data_out_r;
|
| 184 |
+
assign eth_strobe_short = eth_strobe_short_r;
|
| 185 |
+
assign eth_strobe_long = pack_len_nz && pc_r > 3 && category != 0;
|
| 186 |
+
assign pc = pc_d;
|
| 187 |
+
|
| 188 |
+
// Debug only; will be dropped if you don't hook up the xcheck_fault port:
|
| 189 |
+
// Cross-check the IP header checksum we just computed
|
| 190 |
+
reg xcheck_zero=0, xcheck_gate=0, xcheck_ones_d=0;
|
| 191 |
+
reg xcheck_capture=0, xcheck_fault_r=0;
|
| 192 |
+
wire xcheck_ones;
|
| 193 |
+
always @(posedge clk) begin
|
| 194 |
+
xcheck_zero <= pc_r <= 4;
|
| 195 |
+
xcheck_gate <= pc_r >= 20 && pc_r < 40;
|
| 196 |
+
xcheck_ones_d <= xcheck_ones;
|
| 197 |
+
xcheck_capture <= pc_r == 40;
|
| 198 |
+
xcheck_fault_r <= xcheck_capture & ~xcheck_ones & ~xcheck_ones_d;
|
| 199 |
+
end
|
| 200 |
+
ones_chksum xchk(.clk(clk), .clear(xcheck_zero), .gate(xcheck_gate),
|
| 201 |
+
.din(eth_data_out), .all_ones(xcheck_ones));
|
| 202 |
+
assign xcheck_fault = xcheck_fault_r;
|
| 203 |
+
|
| 204 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/crc8e_guts.v
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Hacked to support Ethernet
|
| 2 |
+
module crc8e_guts(
|
| 3 |
+
input clk,
|
| 4 |
+
input gate,
|
| 5 |
+
input first, // set this during the first clock cycle of a new block of data
|
| 6 |
+
input [7:0] d_in,
|
| 7 |
+
output [7:0] d_out,
|
| 8 |
+
output zero
|
| 9 |
+
);
|
| 10 |
+
// https://en.wikipedia.org/wiki/Cyclic_redundancy_check
|
| 11 |
+
parameter wid=32;
|
| 12 |
+
parameter init=32'hffffffff;
|
| 13 |
+
|
| 14 |
+
// Three names are magic to crc_guts.vh:
|
| 15 |
+
// D data in
|
| 16 |
+
// O old CRC value
|
| 17 |
+
// crc new CRC value
|
| 18 |
+
reg [wid-1:0] crc=0;
|
| 19 |
+
wire [7:0] D = d_in;
|
| 20 |
+
wire [wid-1:0] O = first ? init : crc;
|
| 21 |
+
always @(posedge clk) if (gate) begin
|
| 22 |
+
// Machine generated by ./crc_derive -lsb 32 0x4c11db7 8
|
| 23 |
+
// D is the 8-bit input data (lsb-first)
|
| 24 |
+
// crc and O are the new and old 32-bit CRC
|
| 25 |
+
// Generating polynomial is 0x4c11db7 (normal form, leading 1 suppressed)
|
| 26 |
+
// Reference: https://en.wikipedia.org/wiki/Cyclic_redundancy_check
|
| 27 |
+
crc[0] <= D[7]^D[1]^O[24]^O[30];
|
| 28 |
+
crc[1] <= D[7]^D[6]^D[1]^D[0]^O[24]^O[25]^O[30]^O[31];
|
| 29 |
+
crc[2] <= D[7]^D[6]^D[5]^D[1]^D[0]^O[24]^O[25]^O[26]^O[30]^O[31];
|
| 30 |
+
crc[3] <= D[6]^D[5]^D[4]^D[0]^O[25]^O[26]^O[27]^O[31];
|
| 31 |
+
crc[4] <= D[7]^D[5]^D[4]^D[3]^D[1]^O[24]^O[26]^O[27]^O[28]^O[30];
|
| 32 |
+
crc[5] <= D[7]^D[6]^D[4]^D[3]^D[2]^D[1]^D[0]^O[24]^O[25]^O[27]^O[28]^O[29]^O[30]^O[31];
|
| 33 |
+
crc[6] <= D[6]^D[5]^D[3]^D[2]^D[1]^D[0]^O[25]^O[26]^O[28]^O[29]^O[30]^O[31];
|
| 34 |
+
crc[7] <= D[7]^D[5]^D[4]^D[2]^D[0]^O[24]^O[26]^O[27]^O[29]^O[31];
|
| 35 |
+
crc[8] <= D[7]^O[0]^D[6]^D[4]^D[3]^O[24]^O[25]^O[27]^O[28];
|
| 36 |
+
crc[9] <= D[6]^O[1]^D[5]^D[3]^D[2]^O[25]^O[26]^O[28]^O[29];
|
| 37 |
+
crc[10] <= D[7]^D[5]^O[2]^D[4]^D[2]^O[24]^O[26]^O[27]^O[29];
|
| 38 |
+
crc[11] <= D[7]^D[6]^D[4]^O[3]^D[3]^O[24]^O[25]^O[27]^O[28];
|
| 39 |
+
crc[12] <= D[7]^D[6]^D[5]^D[3]^O[4]^D[2]^D[1]^O[24]^O[25]^O[26]^O[28]^O[29]^O[30];
|
| 40 |
+
crc[13] <= D[6]^D[5]^D[4]^D[2]^O[5]^D[1]^D[0]^O[25]^O[26]^O[27]^O[29]^O[30]^O[31];
|
| 41 |
+
crc[14] <= D[5]^D[4]^D[3]^D[1]^O[6]^D[0]^O[26]^O[27]^O[28]^O[30]^O[31];
|
| 42 |
+
crc[15] <= D[4]^D[3]^D[2]^D[0]^O[7]^O[27]^O[28]^O[29]^O[31];
|
| 43 |
+
crc[16] <= D[7]^D[3]^D[2]^O[8]^O[24]^O[28]^O[29];
|
| 44 |
+
crc[17] <= D[6]^D[2]^D[1]^O[9]^O[25]^O[29]^O[30];
|
| 45 |
+
crc[18] <= D[5]^D[1]^D[0]^O[10]^O[26]^O[30]^O[31];
|
| 46 |
+
crc[19] <= D[4]^D[0]^O[11]^O[27]^O[31];
|
| 47 |
+
crc[20] <= D[3]^O[12]^O[28];
|
| 48 |
+
crc[21] <= D[2]^O[13]^O[29];
|
| 49 |
+
crc[22] <= D[7]^O[14]^O[24];
|
| 50 |
+
crc[23] <= D[7]^D[6]^D[1]^O[15]^O[24]^O[25]^O[30];
|
| 51 |
+
crc[24] <= D[6]^D[5]^D[0]^O[16]^O[25]^O[26]^O[31];
|
| 52 |
+
crc[25] <= D[5]^D[4]^O[17]^O[26]^O[27];
|
| 53 |
+
crc[26] <= D[7]^D[4]^D[3]^D[1]^O[18]^O[24]^O[27]^O[28]^O[30];
|
| 54 |
+
crc[27] <= D[6]^D[3]^D[2]^D[0]^O[19]^O[25]^O[28]^O[29]^O[31];
|
| 55 |
+
crc[28] <= D[5]^D[2]^D[1]^O[20]^O[26]^O[29]^O[30];
|
| 56 |
+
crc[29] <= D[4]^D[1]^D[0]^O[21]^O[27]^O[30]^O[31];
|
| 57 |
+
crc[30] <= D[3]^D[0]^O[22]^O[28]^O[31];
|
| 58 |
+
crc[31] <= D[2]^O[23]^O[29];
|
| 59 |
+
end
|
| 60 |
+
wire [7:0] dr = ~crc[wid-1:wid-8]; // note polarity inversion
|
| 61 |
+
assign d_out = {dr[0],dr[1],dr[2],dr[3],dr[4],dr[5],dr[6],dr[7]};
|
| 62 |
+
// note bit order reversal
|
| 63 |
+
|
| 64 |
+
// assign zero = ~(|crc);
|
| 65 |
+
assign zero = crc==32'hc704dd7b;
|
| 66 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/doc/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Figures
|
| 2 |
+
|
| 3 |
+
This directory holds diagrams that document various aspects of Packet Badger.
|
| 4 |
+
The Verilog source code refers to these as appropriate.
|
| 5 |
+
Some of them are also used by the README.md in the root directory.
|
| 6 |
+
|
| 7 |
+
All the .eps files here are created and editable by [xcircuit](http://opencircuitdesign.com/xcircuit/).
|
| 8 |
+
Rules in the associated Makefile convert them to the web-compatible SVG format.
|
| 9 |
+
|
| 10 |
+
### Block Diagram
|
| 11 |
+

|
| 12 |
+
|
| 13 |
+
### Context at the system level
|
| 14 |
+

|
| 15 |
+
|
| 16 |
+
### Attachment of clients:
|
| 17 |
+

|
| 18 |
+
|
| 19 |
+
### Memory gateway (localbus) timing:
|
| 20 |
+

|
| 21 |
+
|
| 22 |
+
### Internal memory addressing:
|
| 23 |
+

|
| 24 |
+
|
| 25 |
+
### Data path in construct.v:
|
| 26 |
+

|
| 27 |
+
|
| 28 |
+
### Design study for a precog upgrade
|
| 29 |
+

|
BerkeleyLab_Bedrock/badger/ethernet_crc_add.v
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Appends 32-bit Ethernet CRC to the end of a packet
|
| 2 |
+
// Also inserts GMII preamble
|
| 3 |
+
//
|
| 4 |
+
// The cycle-by-cycle timing definition for these tasks
|
| 5 |
+
// comes from the raw_s (short) and raw_l (long) strobes;
|
| 6 |
+
// raw_s is valid just for the (incoming) packet data.
|
| 7 |
+
// raw_l is also valid for a few cycles before, and 4 cycles after, that.
|
| 8 |
+
module ethernet_crc_add(
|
| 9 |
+
input clk, // timespec 6.8 ns
|
| 10 |
+
input raw_s,
|
| 11 |
+
input raw_l,
|
| 12 |
+
input [7:0] raw_d,
|
| 13 |
+
output opack_s,
|
| 14 |
+
output [7:0] opack_d
|
| 15 |
+
);
|
| 16 |
+
|
| 17 |
+
// Strobes are easy
|
| 18 |
+
reg raw_s_d=0, raw_l_d=0;
|
| 19 |
+
always @(posedge clk) begin
|
| 20 |
+
raw_s_d <= raw_s;
|
| 21 |
+
raw_l_d <= raw_l;
|
| 22 |
+
end
|
| 23 |
+
wire first_crc = raw_s & ~raw_s_d;
|
| 24 |
+
wire trail = raw_s_d & ~raw_s;
|
| 25 |
+
wire gate_crc;
|
| 26 |
+
wire out_crc_sel;
|
| 27 |
+
|
| 28 |
+
// Instantiation
|
| 29 |
+
wire [7:0] crc_out;
|
| 30 |
+
crc8e_guts #(.wid(32)) crc8e(.clk(clk), .gate(gate_crc),
|
| 31 |
+
.first(first_crc), .d_in(out_crc_sel ? ~crc_out : raw_d),
|
| 32 |
+
.d_out(crc_out), .zero());
|
| 33 |
+
|
| 34 |
+
// Multiplexing
|
| 35 |
+
reg [1:0] crc_cnt=0;
|
| 36 |
+
reg [7:0] opack_r=0;
|
| 37 |
+
assign gate_crc = raw_s | raw_s_d | (crc_cnt != 0);
|
| 38 |
+
assign out_crc_sel = trail | (|crc_cnt);
|
| 39 |
+
always @(posedge clk) begin
|
| 40 |
+
crc_cnt <= out_crc_sel ? crc_cnt+1 : 0;
|
| 41 |
+
opack_r <= out_crc_sel ? crc_out : raw_s ? raw_d : 8'h55;
|
| 42 |
+
end
|
| 43 |
+
assign opack_d = first_crc ? 8'hd5 : opack_r;
|
| 44 |
+
assign opack_s = raw_l | raw_l_d;
|
| 45 |
+
|
| 46 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/flash.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPI Boot Flash programming support in Packet Badger
|
| 2 |
+
|
| 3 |
+
Modern FPGAs typically have the ability to boot from SPI flash.
|
| 4 |
+
Then when operating, those flash pins are available for the fabric
|
| 5 |
+
to interact with. Thus the FPGA can program its own boot flash.
|
| 6 |
+
|
| 7 |
+
Packet Badger includes a set of (synthesizable, portable) Verilog
|
| 8 |
+
modules to take advantage of this, and a host python program to
|
| 9 |
+
manipulate the system.
|
| 10 |
+
|
| 11 |
+
Verilog code:
|
| 12 |
+
|
| 13 |
+
* [spi_flash.v](spi_flash.v)
|
| 14 |
+
* [spi_flash_engine.v](spi_flash_engine.v)
|
| 15 |
+
* [reg_delay.v](../dsp/reg_delay.v)
|
| 16 |
+
|
| 17 |
+
They optionally reference Xilinx primitives ICAP_SPARTAN6 or ICAPE2.
|
| 18 |
+
When running on a Xilinx Spartan 6 or 7-Series FPGA, this allows
|
| 19 |
+
run-time selection among multiple bitfiles stored on a single flash chip.
|
| 20 |
+
|
| 21 |
+
Python (host) code:
|
| 22 |
+
|
| 23 |
+
* [spi_test.py](tests/spi_test.py)
|
| 24 |
+
|
| 25 |
+
## Write protect
|
| 26 |
+
|
| 27 |
+
Modern SPI flash chips include write-protect features. This can be messy
|
| 28 |
+
and complicated. Our goal is to make the system resistant to bricking,
|
| 29 |
+
by holding a "golden image" in a write-protected zone of the flash.
|
| 30 |
+
Two open-hardware example boards designed around that principle are
|
| 31 |
+
|
| 32 |
+
* [Marble](https://github.com/BerkeleyLab/Marble)
|
| 33 |
+
* [Marble-Mini](https://github.com/BerkeleyLab/Marble-Mini)
|
| 34 |
+
|
| 35 |
+
Other COTS boards like the SP605 and AC701 can also be used, but they
|
| 36 |
+
don't have the hardware switch on the flash chip's WP# line that can
|
| 37 |
+
guarantee protection of the golden image.
|
| 38 |
+
|
| 39 |
+
This discussion and software revolves around the write-protect feature
|
| 40 |
+
of a Spansion/Cypress/Infineon S25FL128S
|
| 41 |
+
(note that Spansion merged with Cypress in 2014,
|
| 42 |
+
which was in turn acquired by Infineon in 2020).
|
| 43 |
+
See the Infineon [data sheet for S25FL128S, S25FL256S](https://www.infineon.com/dgdl/Infineon-S25FL128S_S25FL256S_128_Mb_%2816_MB%29_256_Mb_%2832_MB%29_3.0V_SPI_Flash_Memory-DataSheet-v18_00-EN.pdf?fileId=8ac78c8c7d0d8da4017d0ecfb6a64a17),
|
| 44 |
+
001-98283 Rev. *R, 2022-06-10.
|
| 45 |
+
|
| 46 |
+
```
|
| 47 |
+
fc4dff8ef4d8ebf6815c1e994812f8177c917b63c59a4913b7360eef01785af6 Infineon-S25FL128S_S25FL256S_128_Mb_(16_MB)_256_Mb_(32_MB)_3.0V_SPI_Flash_Memory-DataSheet-v19_00-EN.pdf
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
As a metric of the complexity of these chips, note that the data sheet
|
| 51 |
+
is 165 pages long! I think the features discussed here are likely to show up
|
| 52 |
+
on other flash chips, but I can't confirm they are JEDEC-standard.
|
| 53 |
+
|
| 54 |
+
Use of the write-protect feature centers on two registers,
|
| 55 |
+
Status Register 1 (SR1) and Configuration Register 1 (CR1).
|
| 56 |
+
We demand that TBPROT is set, so the protected blocks are at low addresses.
|
| 57 |
+
This is important, because Xilinx FPGAs boot starting at address 0.
|
| 58 |
+
|
| 59 |
+
## Operation
|
| 60 |
+
|
| 61 |
+
Quoting p. 55 of that data sheet:
|
| 62 |
+
"The desired state of TBPROT must be selected during the initial configuration
|
| 63 |
+
of the device during system manufacture; before the first program or erase
|
| 64 |
+
operation on the main flash array. TBPROT must not be programmed after
|
| 65 |
+
programming or erasing is done in the main flash array."
|
| 66 |
+
|
| 67 |
+
Other crucial paragraphs to read are p. 52 about the Status Register
|
| 68 |
+
Write Disable (SRWD) bit SR1[7], and p. 56 about the Freeze Protection
|
| 69 |
+
(FREEZE) bit CR1[0].
|
| 70 |
+
|
| 71 |
+
The board first needs to have a Packet Badger-based bitfile loaded
|
| 72 |
+
over JTAG. Ethernet must be connected and routed to your workstation,
|
| 73 |
+
so you can `ping $IP`. Put your shell in the `badger/tests` directory
|
| 74 |
+
for the steps below.
|
| 75 |
+
|
| 76 |
+
```sh
|
| 77 |
+
python3 spi_test.py --ip $IP --id
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
If this comes back CONFIG_REG (CR1) = 0x00, this chip is likely
|
| 81 |
+
fresh-from-the-factory. Make sure the Write Protect switch is off, then
|
| 82 |
+
|
| 83 |
+
```sh
|
| 84 |
+
python3 spi_test.py --ip $IP --config_init
|
| 85 |
+
python3 spi_test.py --ip $IP --id
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
Now it should report CONFIG_REG (CR1) = 0x21, with the TBPROT and FREEZE
|
| 89 |
+
bits set. Because of the OTP (one-time-programmable) nature of bits in CR1,
|
| 90 |
+
this step has not been extensively tested.
|
| 91 |
+
|
| 92 |
+
To program the golden image at address zero,
|
| 93 |
+
make sure the Write Protect switch is off, use the --id feature
|
| 94 |
+
to check that the FREEZE bit is off (may require a power-cycle), and
|
| 95 |
+
|
| 96 |
+
```sh
|
| 97 |
+
python3 spi_test.py --ip $IP --program $BITFILE --force_write_enable
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
and then turn the Write Protect switch on.
|
| 101 |
+
|
| 102 |
+
To program an application image in the second half of the 16 MByte
|
| 103 |
+
flash chip, leave the Write Protect switch on, and
|
| 104 |
+
|
| 105 |
+
```sh
|
| 106 |
+
python3 spi_test.py --ip $IP --upper --program $BITFILE
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
When running the golden bitfile after a power cycle or hardware reset,
|
| 110 |
+
reboot to that second-half bitfile with
|
| 111 |
+
|
| 112 |
+
```sh
|
| 113 |
+
python3 spi_test.py --ip $IP --reboot7 --upper
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
If you get in trouble, make liberal use of
|
| 117 |
+
|
| 118 |
+
```sh
|
| 119 |
+
python3 spi_test.py --ip $IP --clear_status
|
| 120 |
+
python3 spi_test.py --ip $IP --id
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
## Performance
|
| 124 |
+
|
| 125 |
+
Quick comment about timing, approximate of course.
|
| 126 |
+
With a Kintex 7K160 and its 6693 kByte bitfile,
|
| 127 |
+
|
| 128 |
+
* 1 second boot from flash (SPI_BUSWIDTH 2, CONFIGRATE 33)
|
| 129 |
+
* 4 second program via USB JTAG (openocd adapter_khz 15000)
|
| 130 |
+
* 146 second program flash via Ethernet and spi_flash.v
|
| 131 |
+
* 40 second verify flash via Ethernet and spi_flash.v
|
| 132 |
+
|
| 133 |
+
So while flash is great for deploying production bitfiles, it's not
|
| 134 |
+
the best choice for edit/synthesize/test development cycles.
|
BerkeleyLab_Bedrock/badger/hack_icmp_cksum.v
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Subtracts 0x800 from an ICMP checksum
|
| 2 |
+
// Sounds easy, right? But actually pretty tricky to correctly
|
| 3 |
+
// handle 16-bit one's-complement arithmetic on data flying by 8-bits
|
| 4 |
+
// at a time. Tricky enough that Du got it wrong in icmp_rx.v;
|
| 5 |
+
// that code gets the right checksum only 31/32 of the time.
|
| 6 |
+
// Quoting RFC 792:
|
| 7 |
+
// The checksum is the 16-bit ones's [sic] complement of the one's
|
| 8 |
+
// complement sum of the ICMP message starting with the ICMP Type.
|
| 9 |
+
|
| 10 |
+
// Output is delayed two cycles from input.
|
| 11 |
+
// kick needs to be asserted on the second of the two cycles
|
| 12 |
+
// with the checksum at the input.
|
| 13 |
+
|
| 14 |
+
module hack_icmp_cksum(
|
| 15 |
+
input clk,
|
| 16 |
+
input kick,
|
| 17 |
+
input [7:0] idat,
|
| 18 |
+
output [7:0] odat
|
| 19 |
+
);
|
| 20 |
+
|
| 21 |
+
// Precompute the all-ones condition
|
| 22 |
+
wire ones_i = &idat;
|
| 23 |
+
reg ones_r=0;
|
| 24 |
+
always @(posedge clk) ones_r <= ones_i;
|
| 25 |
+
wire all_ones = ones_i & ones_r;
|
| 26 |
+
|
| 27 |
+
// Insert modified checksum into stream
|
| 28 |
+
wire [15:0] x3;
|
| 29 |
+
reg [7:0] dat1=0, dat2=0;
|
| 30 |
+
always @(posedge clk) begin
|
| 31 |
+
dat1 <= kick ? x3[7:0] : idat;
|
| 32 |
+
dat2 <= kick ? x3[15:8] : dat1;
|
| 33 |
+
end
|
| 34 |
+
|
| 35 |
+
// 16-bit checksum arithmetic
|
| 36 |
+
// Because of the extra inversion, we really add 0x800.
|
| 37 |
+
wire [15:0] x0 = {dat1, idat};
|
| 38 |
+
wire [15:0] x1 = {x0[10:0], x0[15:11]}; // rotate right 11 bits
|
| 39 |
+
wire [15:0] x2 = x1 + 1 + all_ones;
|
| 40 |
+
assign x3 = {x2[4:0], x2[15:5]}; // rotate left 11 bits
|
| 41 |
+
|
| 42 |
+
assign odat = dat2;
|
| 43 |
+
|
| 44 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/hello.v
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Demo client
|
| 2 |
+
module hello(
|
| 3 |
+
input clk,
|
| 4 |
+
// client interface with RTEFI, see doc/clients.eps
|
| 5 |
+
input [10:0] len_c,
|
| 6 |
+
input [7:0] idata,
|
| 7 |
+
input raw_l,
|
| 8 |
+
input raw_s,
|
| 9 |
+
output [7:0] odata
|
| 10 |
+
);
|
| 11 |
+
|
| 12 |
+
parameter n_lat=2;
|
| 13 |
+
|
| 14 |
+
reg [255:0] test_msg_rom = "Hello world from Packet Badger!\n";
|
| 15 |
+
reg [4:0] a;
|
| 16 |
+
reg [7:0] test_msg=0;
|
| 17 |
+
always @(posedge clk) begin
|
| 18 |
+
a <= len_c[4:0] - 9;
|
| 19 |
+
test_msg <= test_msg_rom[{a,3'b0} +: 8];
|
| 20 |
+
end
|
| 21 |
+
|
| 22 |
+
// 13 bits input, 8 bits output, choose to pipeline output
|
| 23 |
+
reg_delay #(.len(n_lat-2), .dw(8)) align(.clk(clk), .gate(1'b1), .reset(1'b0),
|
| 24 |
+
.din(test_msg), .dout(odata));
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/lb_gateway.v
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Simple wrapper of mem_gateway.v
|
| 2 |
+
// Rename ports to get something more familiar to:
|
| 3 |
+
// - newad.py
|
| 4 |
+
// - picorv32 memory bus bridge
|
| 5 |
+
// - xilinx DRP bridge
|
| 6 |
+
// - potential axi-lite/wishbone bridge
|
| 7 |
+
module lb_gateway #(
|
| 8 |
+
parameter n_lat =8,
|
| 9 |
+
parameter read_pipe_len=3
|
| 10 |
+
) (
|
| 11 |
+
input clk, // timespec 6.8 ns
|
| 12 |
+
// client interface with RTEFI, see doc/clients.eps
|
| 13 |
+
input [10:0] len_c,
|
| 14 |
+
input [ 7:0] idata,
|
| 15 |
+
input raw_l,
|
| 16 |
+
input raw_s,
|
| 17 |
+
output [ 7:0] odata,
|
| 18 |
+
// local bus master
|
| 19 |
+
output lb_clk,
|
| 20 |
+
output [23:0] lb_addr,
|
| 21 |
+
output lb_write,
|
| 22 |
+
output lb_read,
|
| 23 |
+
output lb_rvalid,
|
| 24 |
+
output lb_pre_rvalid,
|
| 25 |
+
output lb_prefill,
|
| 26 |
+
output [31:0] lb_wdata,
|
| 27 |
+
input [31:0] lb_rdata
|
| 28 |
+
);
|
| 29 |
+
|
| 30 |
+
wire control_strobe, control_rd;
|
| 31 |
+
wire [read_pipe_len:0] control_pipe_rd;
|
| 32 |
+
|
| 33 |
+
mem_gateway #(
|
| 34 |
+
.n_lat (n_lat),
|
| 35 |
+
.read_pipe_len (read_pipe_len)
|
| 36 |
+
) mem_gateway_i (
|
| 37 |
+
.clk (clk),
|
| 38 |
+
.len_c (len_c),
|
| 39 |
+
.idata (idata),
|
| 40 |
+
.raw_l (raw_l),
|
| 41 |
+
.raw_s (raw_s),
|
| 42 |
+
.odata (odata),
|
| 43 |
+
.addr (lb_addr),
|
| 44 |
+
.control_strobe (control_strobe),
|
| 45 |
+
.control_rd (control_rd),
|
| 46 |
+
.control_rd_valid(lb_rvalid),
|
| 47 |
+
.control_pipe_rd (control_pipe_rd),
|
| 48 |
+
.control_prefill (lb_prefill),
|
| 49 |
+
.data_out (lb_wdata),
|
| 50 |
+
.data_in (lb_rdata)
|
| 51 |
+
);
|
| 52 |
+
|
| 53 |
+
assign lb_clk = clk;
|
| 54 |
+
assign lb_write = control_strobe & ~control_rd;
|
| 55 |
+
assign lb_read = |control_pipe_rd;
|
| 56 |
+
assign lb_pre_rvalid = control_pipe_rd[read_pipe_len-1];
|
| 57 |
+
|
| 58 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/lbus_access.py
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
Access to Packet Badger's localbus gateway
|
| 3 |
+
'''
|
| 4 |
+
# mostly cribbed from FEED/src/python/leep/
|
| 5 |
+
import argparse
|
| 6 |
+
import socket
|
| 7 |
+
import numpy
|
| 8 |
+
import random
|
| 9 |
+
import ast
|
| 10 |
+
# import binascii
|
| 11 |
+
be32 = numpy.dtype('>u4')
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class lbus_access:
|
| 15 |
+
def __init__(self, host, timeout=1.02, port=803, force_burst=False, allow_burst=True, verbose=False):
|
| 16 |
+
self.dest = (host, int(port))
|
| 17 |
+
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
|
| 18 |
+
self.sock.settimeout(timeout)
|
| 19 |
+
self.verbose = verbose
|
| 20 |
+
if force_burst:
|
| 21 |
+
self.burst_avail = True
|
| 22 |
+
elif allow_burst:
|
| 23 |
+
self.burst_avail = self._burst_avail()
|
| 24 |
+
else:
|
| 25 |
+
self.burst_avail = False
|
| 26 |
+
|
| 27 |
+
def _burst_avail(self):
|
| 28 |
+
"""Determines if device supports block-transfer/repeat-count
|
| 29 |
+
"""
|
| 30 |
+
# TODO: Extract device capabilities automatically
|
| 31 |
+
dev_burst_en = False
|
| 32 |
+
|
| 33 |
+
# Ugly, noisy, fragile, and invasive PoC
|
| 34 |
+
msg = numpy.zeros(14, dtype=be32)
|
| 35 |
+
msg[0] = random.randint(0, 0xffffffff)
|
| 36 |
+
msg[1] = msg[0] ^ 0xffffffff
|
| 37 |
+
msg[2] = 0x10000002 # read 2
|
| 38 |
+
msg[3] = 0xa5a5a5a5 # pad
|
| 39 |
+
msg[4] = 0x10000001 # read 1
|
| 40 |
+
msg[5] = 0xa5a5a5a5 # pad
|
| 41 |
+
msg[6] = 0x20000002 # repeat 2 / write 2
|
| 42 |
+
msg[7] = 0x10000001 # read 1 / write data
|
| 43 |
+
msg[8] = 0x10000001 # pad / read 1
|
| 44 |
+
msg[9] = 0xa5a5a5a5 # pad
|
| 45 |
+
msg[10] = 0x20000002 # repeat 2 / write 2
|
| 46 |
+
msg[11] = 0x10000001 # read 1 / write data
|
| 47 |
+
msg[12] = 0x10000002 # pad / read 2
|
| 48 |
+
msg[13] = 0xa5a5a5a5 # pad
|
| 49 |
+
|
| 50 |
+
tosend = msg.tobytes()
|
| 51 |
+
# print("%s Send (%d) %s", self.dest, len(tosend), binascii.hexlify(tosend))
|
| 52 |
+
self.sock.sendto(tosend, self.dest)
|
| 53 |
+
if True:
|
| 54 |
+
reply, src = self.sock.recvfrom(15000)
|
| 55 |
+
if len(reply) == 14*4:
|
| 56 |
+
reply = numpy.frombuffer(reply, be32)
|
| 57 |
+
for n in [0, 1, 2, 4, 6, 7, 10, 11]:
|
| 58 |
+
if reply[n] != msg[n]:
|
| 59 |
+
print("bad mismatch %8.8x != %8.8x" % (reply[n], msg[n]))
|
| 60 |
+
r1 = reply[5]
|
| 61 |
+
r2 = reply[3]
|
| 62 |
+
if msg[8] == reply[8] and r1 == reply[9] and msg[12] == reply[12] and r2 == reply[13]:
|
| 63 |
+
if self.verbose:
|
| 64 |
+
print("Seems to be no-burst")
|
| 65 |
+
return False
|
| 66 |
+
elif r1 == reply[8] and r2 == reply[9] and r1 == reply[12] and r2 == reply[13]:
|
| 67 |
+
if self.verbose:
|
| 68 |
+
print("Seems to be burst")
|
| 69 |
+
return True
|
| 70 |
+
else:
|
| 71 |
+
if self.verbose:
|
| 72 |
+
print("Burst autodetect failed")
|
| 73 |
+
return False
|
| 74 |
+
# for jx, x in enumerate(reply):
|
| 75 |
+
# print("%2d %8.8x" % (jx, x))
|
| 76 |
+
|
| 77 |
+
return dev_burst_en
|
| 78 |
+
|
| 79 |
+
def _exchange(self, addrs, values=None, drop_reply=False, burst=False):
|
| 80 |
+
"""Exchange a single low level message
|
| 81 |
+
"""
|
| 82 |
+
|
| 83 |
+
if not burst:
|
| 84 |
+
msg = numpy.zeros(2+2*len(addrs), dtype=be32)
|
| 85 |
+
else:
|
| 86 |
+
msg = numpy.zeros(2+2+len(addrs), dtype=be32)
|
| 87 |
+
|
| 88 |
+
msg[0] = random.randint(0, 0xffffffff)
|
| 89 |
+
msg[1] = msg[0] ^ 0xffffffff
|
| 90 |
+
|
| 91 |
+
if not burst:
|
| 92 |
+
for i, (A, V) in enumerate(zip(addrs, values), 1):
|
| 93 |
+
A &= 0x00ffffff
|
| 94 |
+
if V is None:
|
| 95 |
+
A |= 0x10000000
|
| 96 |
+
msg[2*i] = A
|
| 97 |
+
msg[2*i+1] = V or 0
|
| 98 |
+
else:
|
| 99 |
+
RC = (len(addrs) & 0x00ffffff) | 0x20000000
|
| 100 |
+
A = addrs[0]
|
| 101 |
+
A &= 0x00ffffff
|
| 102 |
+
if values[0] is None:
|
| 103 |
+
A |= 0x10000000
|
| 104 |
+
msg[2] = RC
|
| 105 |
+
msg[3] = A
|
| 106 |
+
for i, V in enumerate(values, 4):
|
| 107 |
+
msg[i] = V or 0
|
| 108 |
+
|
| 109 |
+
tosend = msg.tobytes()
|
| 110 |
+
if False:
|
| 111 |
+
mm = ".".join(["%8.8x" % x for x in msg])
|
| 112 |
+
print("%s Send (%d) %s" % (self.dest, len(tosend), mm))
|
| 113 |
+
self.sock.sendto(tosend, self.dest)
|
| 114 |
+
|
| 115 |
+
if drop_reply:
|
| 116 |
+
return None
|
| 117 |
+
|
| 118 |
+
while True:
|
| 119 |
+
reply, src = self.sock.recvfrom(15000)
|
| 120 |
+
# print("%s Recv (%d) %s", src, len(reply), binascii.hexlify(reply))
|
| 121 |
+
|
| 122 |
+
byte_align = 8 if not burst else 4
|
| 123 |
+
if len(reply) % byte_align:
|
| 124 |
+
reply = reply[:-(len(reply) % byte_align)]
|
| 125 |
+
|
| 126 |
+
if len(tosend) != len(reply):
|
| 127 |
+
print("Reply truncated %d %d" % (len(tosend), len(reply)))
|
| 128 |
+
continue
|
| 129 |
+
|
| 130 |
+
reply = numpy.frombuffer(reply, be32)
|
| 131 |
+
if (msg[:2] != reply[:2]).any():
|
| 132 |
+
print('Ignore reply w/o matching nonce %s %s' % (msg[:2], reply[:2]))
|
| 133 |
+
continue
|
| 134 |
+
elif not burst and (msg[2::2] != reply[2::2]).any():
|
| 135 |
+
print('reply addresses are out of order')
|
| 136 |
+
continue
|
| 137 |
+
elif burst and (msg[2:3] != reply[2:3]).any():
|
| 138 |
+
print('Non-matching start address')
|
| 139 |
+
continue
|
| 140 |
+
break
|
| 141 |
+
|
| 142 |
+
ret = reply[3::2] if not burst else reply[4::1]
|
| 143 |
+
return ret
|
| 144 |
+
|
| 145 |
+
def exchange(self, addrs, values=None, drop_reply=False):
|
| 146 |
+
"""Accepts a list of address and values (None to read).
|
| 147 |
+
Returns a numpy.ndarray in the same order.
|
| 148 |
+
"""
|
| 149 |
+
addrs = list(addrs)
|
| 150 |
+
|
| 151 |
+
consec = False
|
| 152 |
+
# Check for consecutive addresses if burst mode available
|
| 153 |
+
if self.burst_avail and len(addrs) > 1 and (addrs == list(range(addrs[0], addrs[-1]+1))):
|
| 154 |
+
consec = True
|
| 155 |
+
|
| 156 |
+
if values is None:
|
| 157 |
+
values = [None]*len(addrs)
|
| 158 |
+
else:
|
| 159 |
+
values = list(values)
|
| 160 |
+
|
| 161 |
+
ret = numpy.zeros(len(addrs), be32)
|
| 162 |
+
n_tx = 255 if consec else 127
|
| 163 |
+
for i in range(0, len(addrs), n_tx):
|
| 164 |
+
A, B = addrs[i:i+n_tx], values[i:i+n_tx]
|
| 165 |
+
|
| 166 |
+
P = self._exchange(A, B, drop_reply=drop_reply, burst=consec)
|
| 167 |
+
if not drop_reply:
|
| 168 |
+
ret[i:i+n_tx] = P
|
| 169 |
+
|
| 170 |
+
return ret
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
def read_write(dev, args):
|
| 174 |
+
for pair in args.reg:
|
| 175 |
+
reg, _eq, val = pair.partition('=')
|
| 176 |
+
reg = ast.literal_eval(reg)
|
| 177 |
+
if not len(val): # read operation
|
| 178 |
+
val = None
|
| 179 |
+
else:
|
| 180 |
+
val = ast.literal_eval(val)
|
| 181 |
+
|
| 182 |
+
retval = dev.exchange([reg], [val])
|
| 183 |
+
if val is None:
|
| 184 |
+
print("%s: \t%08x" % (reg, retval[0]))
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def mem_read(dev, args):
|
| 188 |
+
for pair in args.mem:
|
| 189 |
+
baseaddr, _eq, length = pair.partition(':')
|
| 190 |
+
baseaddr = ast.literal_eval(baseaddr)
|
| 191 |
+
length = ast.literal_eval(length)
|
| 192 |
+
|
| 193 |
+
retmem = dev.exchange(range(baseaddr, baseaddr+length))
|
| 194 |
+
if args.string:
|
| 195 |
+
print("".join([chr(x) for x in retmem]))
|
| 196 |
+
else:
|
| 197 |
+
print(retmem)
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
if __name__ == "__main__":
|
| 201 |
+
p = argparse.ArgumentParser()
|
| 202 |
+
p.add_argument('-a', '--address', help='IP address of device', default='localhost')
|
| 203 |
+
p.add_argument('-p', '--port', help='UDP port for I/O', default=803)
|
| 204 |
+
p.add_argument('-t', '--timeout', help='UDP timeout, in seconds', type=float, default=1.02)
|
| 205 |
+
p.add_argument('--string', help='Format output as string', action='store_true', dest='string')
|
| 206 |
+
|
| 207 |
+
sp = p.add_subparsers()
|
| 208 |
+
s = sp.add_parser('reg', help='read/write registers')
|
| 209 |
+
s.set_defaults(func=read_write)
|
| 210 |
+
s.add_argument('reg', nargs='+', help='register[=newvalue]')
|
| 211 |
+
|
| 212 |
+
s = sp.add_parser('mem', help='read contiguous memory')
|
| 213 |
+
s.set_defaults(func=mem_read)
|
| 214 |
+
s.add_argument('mem', nargs='+', help='baseaddr:size')
|
| 215 |
+
args = p.parse_args()
|
| 216 |
+
|
| 217 |
+
lbus_acc = lbus_access(args.address, timeout=args.timeout, port=args.port, force_burst=False)
|
| 218 |
+
|
| 219 |
+
args.func(lbus_acc, args)
|
BerkeleyLab_Bedrock/badger/mac_subset.v
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module mac_subset #(
|
| 2 |
+
parameter mac_aw=10, // 16-bit words
|
| 3 |
+
parameter big_endian=0,
|
| 4 |
+
parameter latency=256,
|
| 5 |
+
parameter stretch=4, // minimum value 2, should be 4 for GMII
|
| 6 |
+
parameter ifg=24 // must have more padding than just Ethernet IFG
|
| 7 |
+
) (
|
| 8 |
+
// connect the 2 below to an external 16 bit dual port ram
|
| 9 |
+
output [mac_aw - 1: 0] host_raddr,
|
| 10 |
+
input [15:0] host_rdata,
|
| 11 |
+
// address where we should start transmitting from
|
| 12 |
+
input [mac_aw - 1: 0] buf_start_addr,
|
| 13 |
+
// set start to trigger transmit, wait for done, reset start
|
| 14 |
+
input tx_mac_start,
|
| 15 |
+
output tx_mac_done,
|
| 16 |
+
// crucial information from input scanner
|
| 17 |
+
input scanner_busy,
|
| 18 |
+
// Connection to output multiplexer, right after xformer.v,
|
| 19 |
+
// data path will get routed to have CRC added, strobes are
|
| 20 |
+
// as needed by that step: strobe_s includes data only,
|
| 21 |
+
// strobe l includes time slots for GMII preamble and CRC.
|
| 22 |
+
input tx_clk,
|
| 23 |
+
output strobe_s,
|
| 24 |
+
output strobe_l,
|
| 25 |
+
output [7:0] mac_data
|
| 26 |
+
);
|
| 27 |
+
|
| 28 |
+
reg host_start_=0;
|
| 29 |
+
always @(posedge tx_clk) begin
|
| 30 |
+
host_start_ <= tx_mac_start;
|
| 31 |
+
end
|
| 32 |
+
|
| 33 |
+
// Instantiate MAC
|
| 34 |
+
wire req;
|
| 35 |
+
wire [10:0] len_req;
|
| 36 |
+
wire mac_strobe;
|
| 37 |
+
test_tx_mac #(
|
| 38 |
+
.mac_aw(mac_aw)
|
| 39 |
+
) mac(
|
| 40 |
+
.clk(tx_clk),
|
| 41 |
+
.host_addr(host_raddr),
|
| 42 |
+
.host_d(host_rdata),
|
| 43 |
+
.start(host_start_),
|
| 44 |
+
.buf_start_addr(buf_start_addr),
|
| 45 |
+
.done(tx_mac_done),
|
| 46 |
+
.req(req),
|
| 47 |
+
.len_req(len_req),
|
| 48 |
+
.strobe(mac_strobe),
|
| 49 |
+
.mac_data(mac_data)
|
| 50 |
+
);
|
| 51 |
+
|
| 52 |
+
// Move scanner_busy to tx_clk domain for use by precog
|
| 53 |
+
// Better to pull this step up to rtefi_center?
|
| 54 |
+
wire scanner_busy_tx;
|
| 55 |
+
reg_tech_cdc scanner_busy_cdc(.I(scanner_busy), .C(tx_clk), .O(scanner_busy_tx));
|
| 56 |
+
|
| 57 |
+
// Instantiate precog
|
| 58 |
+
wire clear_to_send;
|
| 59 |
+
wire [10:0] precog_width = len_req + 2*ifg;
|
| 60 |
+
precog #(
|
| 61 |
+
.PAW (11),
|
| 62 |
+
.LATENCY (latency+ifg)
|
| 63 |
+
) precog (
|
| 64 |
+
.clk (tx_clk),
|
| 65 |
+
.tx_packet_width (precog_width),
|
| 66 |
+
.scanner_busy (scanner_busy_tx),
|
| 67 |
+
.request_to_send (req),
|
| 68 |
+
.clear_to_send (clear_to_send)
|
| 69 |
+
);
|
| 70 |
+
|
| 71 |
+
// Manipulate simple strobe from precog
|
| 72 |
+
// final system wants 4 cycles lead (for GMII preamble) and
|
| 73 |
+
// 4 cycle trailer (for CRC) on strobe_l compared to strobe_s.
|
| 74 |
+
// TODO this should be moved to precog
|
| 75 |
+
reg [stretch-1:0] strobe_sr1=0;
|
| 76 |
+
always @(posedge tx_clk) strobe_sr1 <= {strobe_sr1[stretch-2:0], clear_to_send};
|
| 77 |
+
reg [stretch-1:0] strobe_sr2=0;
|
| 78 |
+
always @(posedge tx_clk) strobe_sr2 <= {strobe_sr2[stretch-2:0], req};
|
| 79 |
+
assign mac_strobe = strobe_sr1[stretch-1] & req;
|
| 80 |
+
assign strobe_s = mac_strobe;
|
| 81 |
+
assign strobe_l = clear_to_send & strobe_sr2[stretch-1];
|
| 82 |
+
|
| 83 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/mem_gate.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Lightweight Address Space Serialization
|
| 2 |
+
|
| 3 |
+
LASS is an encoding of reads and writes to a traditional VME-like address space.
|
| 4 |
+
It is designed for transport over UDP, and has a coordinated set of features
|
| 5 |
+
that make it useful for data exchange between a commodity computer master and
|
| 6 |
+
an FPGA slave, with high throughput and controlled latency.
|
| 7 |
+
|
| 8 |
+
LASS is agnostic as to the details of the bus that is driven; it is suitable
|
| 9 |
+
for use with AXI, Wishbone, or the minimalist local bus in use by LBNL ATG.
|
| 10 |
+
The underlying bus configuration is fixed at 32 bits data, 24 bits of
|
| 11 |
+
word-address. Byte access is not supported. Of course, fewer address bits
|
| 12 |
+
and narrower data words can be accommodated with padding.
|
| 13 |
+
|
| 14 |
+
## Packet structure
|
| 15 |
+
|
| 16 |
+
LASS packets are composed of a 64-bit transaction ID followed by a string of
|
| 17 |
+
consecutive transactions.
|
| 18 |
+
|
| 19 |
+
Two types of transactions are supported. A single-beat transaction where single read
|
| 20 |
+
or write bus cycles are encoded, and a more complex, block-transfer based, where a
|
| 21 |
+
burst of reads or writes to consecutive addresses are encoded in a more efficient
|
| 22 |
+
manner.
|
| 23 |
+
|
| 24 |
+
A single-beat transaction is encoded in 64 bits and is composed of command, address
|
| 25 |
+
and data fields. The diagram below shows how this transaction type can be used to
|
| 26 |
+
form a simple packet containing two single-beat read or write transactions.
|
| 27 |
+
|
| 28 |
+
```
|
| 29 |
+
0 1 2 3
|
| 30 |
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
| 31 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 32 |
+
| Transaction ID [31:0] |
|
| 33 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 34 |
+
| Transaction ID [63:32] |
|
| 35 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 36 |
+
| Command | Address 0 |
|
| 37 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 38 |
+
| Data 0 |
|
| 39 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 40 |
+
| Command | Address 1 |
|
| 41 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 42 |
+
| Data 1 |
|
| 43 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
**NOTE:** This and all other packet diagrams follow the convention used in RFC-791,
|
| 47 |
+
whereby bytes are shown as they are sent 'on the wire', i.e., network-byte-order.
|
| 48 |
+
|
| 49 |
+
The packet space consumed by a block-transfer transaction depends on how many data
|
| 50 |
+
beats are being read or written. At a minimum, this type of transaction can be encoded
|
| 51 |
+
in 96 bits and adds an additional command and a repetition-count field to the
|
| 52 |
+
single-beat transaction described previously. The additional command field is used
|
| 53 |
+
to signal that the transaction being decoded is of type 'burst'. The following diagram
|
| 54 |
+
depicts the structure of a packet containing a single block-transfer transaction where
|
| 55 |
+
two beats of data are either read or written.
|
| 56 |
+
```
|
| 57 |
+
0 1 2 3
|
| 58 |
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
| 59 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 60 |
+
| Transaction ID [31:0] |
|
| 61 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 62 |
+
| Transaction ID [63:32] |
|
| 63 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 64 |
+
| Cmd (Burst) | Repetition Count (2) |
|
| 65 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 66 |
+
| Command | Address 0 |
|
| 67 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 68 |
+
| Data 0 |
|
| 69 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 70 |
+
| Data 1 |
|
| 71 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
Note that each transmitted packet can string together any combination of these two
|
| 75 |
+
transaction types, provided the maximum packet length is not exceeded (see section
|
| 76 |
+
on practical considerations). This can be useful when, e.g., a long array and the
|
| 77 |
+
status register indicating its validity must both be read, and splitting the operation
|
| 78 |
+
into two packets is not desirable. The diagram below shows how such a packet could
|
| 79 |
+
be structured.
|
| 80 |
+
|
| 81 |
+
```
|
| 82 |
+
0 1 2 3
|
| 83 |
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
| 84 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 85 |
+
| Transaction ID [31:0] |
|
| 86 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 87 |
+
| Transaction ID [63:32] |
|
| 88 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 89 |
+
| Command | Address 0 |
|
| 90 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 91 |
+
| Data 0 |
|
| 92 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 93 |
+
| Cmd (Burst) | Repetition Count (3) |
|
| 94 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 95 |
+
| Command | Address 1 |
|
| 96 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 97 |
+
| Data 1 |
|
| 98 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 99 |
+
| Data 2 |
|
| 100 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 101 |
+
| Data 3 |
|
| 102 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
## Data encoding
|
| 106 |
+
|
| 107 |
+
For both transaction types, the bit-widths add up such that all transactions
|
| 108 |
+
start on a 32-bit boundary. Data encoding is big-endian, a.k.a. network byte order.
|
| 109 |
+
|
| 110 |
+
In order to preserve 32-bit boundaries, the Command and Repetition Count fields
|
| 111 |
+
are oversized in relation to the information they convey.
|
| 112 |
+
|
| 113 |
+
The 8-bit Command field carries a single 2-bit operation sub-field (OP), according to the
|
| 114 |
+
following encoding:
|
| 115 |
+
```
|
| 116 |
+
0 1 2 3 4 5 6 7
|
| 117 |
+
+--+--+--+--+--+--+--+--+
|
| 118 |
+
| RSV | OP | RSV |
|
| 119 |
+
+--+--+--+--+--+--+--+--+
|
| 120 |
+
|
| 121 |
+
OP [1:0]:
|
| 122 |
+
2'b00 - Write
|
| 123 |
+
2'b01 - Read
|
| 124 |
+
2'b10 - Burst
|
| 125 |
+
2'b11 - Reserved
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
N.B.: Reserved bits should be set to 0 by software. Failing to do this may result
|
| 129 |
+
in undefined behavior, since they may be defined in some future revision. One valid
|
| 130 |
+
response from the FPGA is therefore to drop packets that have unused bits set.
|
| 131 |
+
|
| 132 |
+
The 24-bit Repetition Count field only uses 9 bits to encode the actual repetition count, as
|
| 133 |
+
shown below. Note that while the width of the COUNT sub-field places an upper bound on
|
| 134 |
+
the number of data beats that can be transferred in a single packet, typical UDP
|
| 135 |
+
packet sizes place additional restrictions on this number. These limitations are
|
| 136 |
+
outlined in the next section.
|
| 137 |
+
```
|
| 138 |
+
0 1 2
|
| 139 |
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
|
| 140 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 141 |
+
| Reserved | COUNT |
|
| 142 |
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 143 |
+
|
| 144 |
+
COUNT [8:0]:
|
| 145 |
+
9'd0 - Illegal
|
| 146 |
+
9'd1 - 1 Beat
|
| 147 |
+
9'd2 - 2 Beats
|
| 148 |
+
...
|
| 149 |
+
9'dN - N Beats
|
| 150 |
+
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
## Practical considerations
|
| 154 |
+
|
| 155 |
+
A key design element of this protocol is that every reply packet has
|
| 156 |
+
the same structure and length as the corresponding request packet.
|
| 157 |
+
Read requests put padding in the place where results will be returned;
|
| 158 |
+
replies to write requests echo the data that was written.
|
| 159 |
+
This balance naturally avoids overloading the reply channel, at least
|
| 160 |
+
in the common case of wire or fiber Ethernet deployments, because they
|
| 161 |
+
are full-duplex with symmetric bandwidth.
|
| 162 |
+
In this context, the processing logic embedded in the FPGA
|
| 163 |
+
can guarantee it will reply to every request.
|
| 164 |
+
|
| 165 |
+
The 64-bit ID can be any value chosen by the host, and will simply be echoed
|
| 166 |
+
by the FPGA. This gives the software an easy mechanism to match up received
|
| 167 |
+
packets with outstanding requests.
|
| 168 |
+
|
| 169 |
+
In a typical Ethernet environment with 1500 MTU, UDP packets can have a
|
| 170 |
+
maximum payload size of 1472 octets. Accounting for the 64-bit ID, there
|
| 171 |
+
is space for a maximum of 183 single-beat transactions per packet.
|
| 172 |
+
|
| 173 |
+
Likewise, it is possible to fill a packet with a block-transfer transaction with
|
| 174 |
+
364 data words, thus setting a practical limit on the values that can be used in
|
| 175 |
+
the Repetition Count block.
|
| 176 |
+
|
| 177 |
+
Exceeding the Ethernet MTU will trigger fragmentation on the software side,
|
| 178 |
+
which both is theoretically undesirable, and practically not supported by
|
| 179 |
+
typical FPGA UDP/IP implementations.
|
| 180 |
+
|
| 181 |
+
Driver software should have the maximum packet size easily configurable,
|
| 182 |
+
to be adaptable to changes in MTU or additional protocol layering.
|
| 183 |
+
An authentication layer could reduce the available packet size by 16 octets.
|
| 184 |
+
|
| 185 |
+
## Implementation and discussion
|
| 186 |
+
|
| 187 |
+
A subset of LASS, without the repeat-count feature, has been used at LBNL
|
| 188 |
+
since about 2010. Its FPGA-side implementation was rewritten in 2018
|
| 189 |
+
(Packet Badger) to operate properly on high-traffic networks.
|
| 190 |
+
This new version gives stronger real-time guarantees, and responds correctly
|
| 191 |
+
to "simultaneous" requests from multiple hosts/masters.
|
| 192 |
+
|
| 193 |
+
For maximum compatibility with legacy software that might set unused control
|
| 194 |
+
bits to non-zero, the implementation in mem_gateway.v does _not_ enable the
|
| 195 |
+
repeat count feature by default. Engaging it requires setting the
|
| 196 |
+
enable_bursts parameter to 1.
|
| 197 |
+
|
| 198 |
+
This feature set is extremely similar to EtherBone, sharing much of the
|
| 199 |
+
motivation and boundary conditions. LASS is a bit more granular, is limited
|
| 200 |
+
to 24-bit addresses instead of 32, and is not specialized for Wishbone.
|
| 201 |
+
It would be interesting if someone rewrote or ported the EtherBone code
|
| 202 |
+
base/protocol as a plug-in to Packet Badger.
|
| 203 |
+
|
| 204 |
+
It's relatively easy to attach a simulated LASS FPGA-end to a real UDP port,
|
| 205 |
+
to exercise the combination of software and (virtual) hardware for debugging.
|
| 206 |
+
Packet Badger includes two demos of this setup, one using Verilator and one
|
| 207 |
+
using Icarus Verilog.
|
| 208 |
+
|
| 209 |
+
LASS as implemented on Packet Badger (including Ethernet/IP/UDP and other
|
| 210 |
+
features like ARP and ICMP echo, for attachment to a GMII PHY) occupies about
|
| 211 |
+
1100 LUTs of Xilinx Spartan-6 or 7-Series chips. [Comparison to EtherBone?]
|
BerkeleyLab_Bedrock/badger/mem_gateway.v
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Uber-simple mapping of a UDP packet to a register read/write port.
|
| 2 |
+
// Lead with 64 bits of padding (sequence number, ID, nonce, ...),
|
| 3 |
+
// then alternate 32 bits of control+address with data.
|
| 4 |
+
// Stick with 24 bits of address, leave 8 bits for control.
|
| 5 |
+
// One of those control bits is the R/W line.
|
| 6 |
+
// Every packet is returned to the sender with the read data filled in.
|
| 7 |
+
// Local bus read latency is fixed, configurable at compile time.
|
| 8 |
+
// Uses standard network byte order (big endian).
|
| 9 |
+
//
|
| 10 |
+
// This version has one more feature (disabled by default for paranoid
|
| 11 |
+
// compatibility reasons, see the enable_bursts parameter), where a repeat
|
| 12 |
+
// count for the following operation can be specified. The address
|
| 13 |
+
// autoincrements in that case, and each repeated operation (read or write)
|
| 14 |
+
// consumes one more 32-bit data field in the input stream. This feature
|
| 15 |
+
// has been tested, but so far it lacks meaningful software support.
|
| 16 |
+
//
|
| 17 |
+
// For a longer description of the on-the-wire protocol, see mem_gate.md
|
| 18 |
+
// Software and local-bus compatible with mem_gateway in ethernet-core.
|
| 19 |
+
|
| 20 |
+
// The control_rd port (a.k.a. not write) is just a level that changes at
|
| 21 |
+
// the start of each transaction, timing exactly like addr and data_out.
|
| 22 |
+
//
|
| 23 |
+
// control_pipe_rd is new; it's for people who want to pay attention to
|
| 24 |
+
// the pipelining of each read operation. It shows the strobe propagating
|
| 25 |
+
// all the way from the start of the read request to the cycle (marked by
|
| 26 |
+
// control_rd_valid, exactly equal to control_pipe_read[read_pipe_len]) when
|
| 27 |
+
// this module latches data_in. Note that the "active" bit(s) flow through
|
| 28 |
+
// all read_pipe_len cycles of activity, plus one more at the end, and thus
|
| 29 |
+
// has a possibly surprising length.
|
| 30 |
+
//
|
| 31 |
+
// If read_pipe_len is increased, and bus cycles are spaced close together
|
| 32 |
+
// (traditionally every 8 cycles, goes down to every 4 when bursts are used)
|
| 33 |
+
// there can be multiple bus transactions in the pipeline simultaneously.
|
| 34 |
+
|
| 35 |
+
// Write operations start on the cycle marked by control_write.
|
| 36 |
+
// At the moment, there is no check that they complete, so any pipelining
|
| 37 |
+
// that takes place is outside the purview of this module.
|
| 38 |
+
|
| 39 |
+
module mem_gateway #(
|
| 40 |
+
parameter read_pipe_len=3, // minimum allowed value is 1
|
| 41 |
+
parameter n_lat=8, // minimum allowed value is 5 + read_pipe_len
|
| 42 |
+
parameter enable_bursts=0
|
| 43 |
+
) (
|
| 44 |
+
input clk, // timespec 6.8 ns
|
| 45 |
+
// client interface with RTEFI, see doc/clients.eps
|
| 46 |
+
input [10:0] len_c,
|
| 47 |
+
input [7:0] idata,
|
| 48 |
+
input raw_l,
|
| 49 |
+
input raw_s,
|
| 50 |
+
output [7:0] odata,
|
| 51 |
+
// local bus
|
| 52 |
+
output [23:0] addr,
|
| 53 |
+
output control_strobe,
|
| 54 |
+
output control_rd,
|
| 55 |
+
output control_write,
|
| 56 |
+
output control_rd_valid,
|
| 57 |
+
output control_prefill,
|
| 58 |
+
// length of control_pipe_rd is read_pipe_len+1, see above
|
| 59 |
+
output [read_pipe_len:0] control_pipe_rd,
|
| 60 |
+
output [31:0] data_out,
|
| 61 |
+
input [31:0] data_in
|
| 62 |
+
);
|
| 63 |
+
|
| 64 |
+
// Pipeline match
|
| 65 |
+
wire [7:0] pdata;
|
| 66 |
+
reg_delay #(.len(read_pipe_len+1), .dw(8)) align(.clk(clk), .gate(1'b1), .reset(1'b0),
|
| 67 |
+
.din(idata), .dout(pdata));
|
| 68 |
+
|
| 69 |
+
// Create localbus output signals
|
| 70 |
+
reg [8:0] repeat_count=0;
|
| 71 |
+
reg [23:0] isr=0; // input shift register
|
| 72 |
+
wire [31:0] next_isr = {isr, idata};
|
| 73 |
+
reg [63:0] big_r=0; // command, address, data
|
| 74 |
+
reg [1:0] c4=0;
|
| 75 |
+
reg data_phase=0;
|
| 76 |
+
reg pre_body=0, body=0;
|
| 77 |
+
reg do_op=0;
|
| 78 |
+
wire next_do_op = body & &c4 & data_phase;
|
| 79 |
+
wire set_repeat = ~data_phase & next_isr[29] & enable_bursts;
|
| 80 |
+
wire set_repeat_view = body & &c4 & set_repeat; // Debug signal
|
| 81 |
+
reg inc_address=0;
|
| 82 |
+
always @(posedge clk) begin
|
| 83 |
+
isr <= next_isr[23:0];
|
| 84 |
+
c4 <= raw_s ? c4+1 : 0;
|
| 85 |
+
if (&c4) pre_body <= 1;
|
| 86 |
+
if (&c4 & pre_body) body <= 1;
|
| 87 |
+
if (~raw_s) begin // reset between packets
|
| 88 |
+
pre_body <= 0;
|
| 89 |
+
body <= 0;
|
| 90 |
+
end
|
| 91 |
+
if (body & &c4) begin
|
| 92 |
+
inc_address <= 0;
|
| 93 |
+
if (set_repeat) begin
|
| 94 |
+
repeat_count <= next_isr[8:0] - 1;
|
| 95 |
+
end else if (~data_phase) begin
|
| 96 |
+
data_phase <= 1;
|
| 97 |
+
big_r[63:32] <= next_isr;
|
| 98 |
+
end else if (|repeat_count) begin
|
| 99 |
+
big_r[31:0] <= next_isr;
|
| 100 |
+
repeat_count <= repeat_count - 1;
|
| 101 |
+
inc_address <= 1;
|
| 102 |
+
end else begin
|
| 103 |
+
big_r[31:0] <= next_isr;
|
| 104 |
+
data_phase <= 0;
|
| 105 |
+
end
|
| 106 |
+
if (inc_address) big_r[63:32] <= big_r[63:32] + 1;
|
| 107 |
+
end
|
| 108 |
+
do_op <= next_do_op;
|
| 109 |
+
end
|
| 110 |
+
assign addr = big_r[23+32:32];
|
| 111 |
+
assign data_out = big_r[31:0];
|
| 112 |
+
assign control_rd = big_r[28+32];
|
| 113 |
+
assign control_strobe = do_op;
|
| 114 |
+
assign control_write = control_strobe & ~control_rd;
|
| 115 |
+
|
| 116 |
+
// Keep track of the read pipeline
|
| 117 |
+
reg [read_pipe_len-1:0] read_pipe_markers=0;
|
| 118 |
+
wire read_op = control_strobe & control_rd;
|
| 119 |
+
always @(posedge clk) read_pipe_markers <= {read_pipe_markers[read_pipe_len-2:0], read_op};
|
| 120 |
+
assign control_pipe_rd = {read_pipe_markers, read_op};
|
| 121 |
+
wire capture = control_pipe_rd[read_pipe_len];
|
| 122 |
+
assign control_rd_valid = capture;
|
| 123 |
+
|
| 124 |
+
// capture result
|
| 125 |
+
reg [31:0] osr=0;
|
| 126 |
+
always @(posedge clk) begin
|
| 127 |
+
osr <= {osr[23:0], pdata};
|
| 128 |
+
if (capture) osr <= data_in;
|
| 129 |
+
end
|
| 130 |
+
wire [7:0] xdata = osr[31:24]; // Data to be transmitted
|
| 131 |
+
|
| 132 |
+
// Final alignment of the Tx data with that of all the other clients
|
| 133 |
+
reg_delay #(.len(n_lat-read_pipe_len-5), .dw(8)) finale(.clk(clk),
|
| 134 |
+
.gate(1'b1), .reset(1'b0),
|
| 135 |
+
.din(xdata), .dout(odata));
|
| 136 |
+
|
| 137 |
+
// Experimental - leading edge detect on raw_l
|
| 138 |
+
reg raw_l_r=0, control_prefill_r;
|
| 139 |
+
always @(posedge clk) begin
|
| 140 |
+
raw_l_r <= raw_l;
|
| 141 |
+
control_prefill_r <= raw_l & ~raw_l_r;
|
| 142 |
+
end
|
| 143 |
+
assign control_prefill = control_prefill_r;
|
| 144 |
+
|
| 145 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/ones_chksum.v
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// 16-bit ones-complement checksum calculator
|
| 2 |
+
// Applies to all of IP header, ICMP, and UDP checksums
|
| 3 |
+
// Well, difficult to use with UDP because of its pathological
|
| 4 |
+
// inclusion of _two_ copies of the UDP length.
|
| 5 |
+
// mostly cribbed from core/assemble_eth.v
|
| 6 |
+
|
| 7 |
+
module ones_chksum(
|
| 8 |
+
input clk,
|
| 9 |
+
input clear,
|
| 10 |
+
input gate,
|
| 11 |
+
input [7:0] din,
|
| 12 |
+
output [7:0] sum,
|
| 13 |
+
output all_ones
|
| 14 |
+
);
|
| 15 |
+
|
| 16 |
+
reg [7:0] chksum=0, chksum1=0;
|
| 17 |
+
reg chksum_carry=0;
|
| 18 |
+
always @(posedge clk) begin
|
| 19 |
+
if (clear) {chksum_carry, chksum} <= 9'h0;
|
| 20 |
+
else if (gate) {chksum_carry, chksum} <=
|
| 21 |
+
chksum1 + din + chksum_carry;
|
| 22 |
+
if (clear) chksum1 <= 8'h0;
|
| 23 |
+
else if (gate) chksum1 <= chksum;
|
| 24 |
+
end
|
| 25 |
+
assign sum = ~(chksum1 + chksum_carry);
|
| 26 |
+
assign all_ones = &chksum;
|
| 27 |
+
|
| 28 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/packet_categorize.v
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Reduce number of bits representing the category
|
| 2 |
+
// of a Packet Badger Rx packet from 8 to 4.
|
| 3 |
+
// Keep the categories here in-sync with badger_stat.py.
|
| 4 |
+
// Output is delayed one cycle; clock domain is unchanged.
|
| 5 |
+
// 0: not used
|
| 6 |
+
// 1: failed CRC
|
| 7 |
+
// 2: ARP for us
|
| 8 |
+
// 3: not MAC-addressed for us
|
| 9 |
+
// 4: packet type is not IP
|
| 10 |
+
// 5: other unrecognized
|
| 11 |
+
// 6: ICMP
|
| 12 |
+
// 7: not used
|
| 13 |
+
// 8-15: UDP to a configured port
|
| 14 |
+
|
| 15 |
+
module packet_categorize(
|
| 16 |
+
input clk,
|
| 17 |
+
input strobe,
|
| 18 |
+
input [7:0] status, // from Badger's scanner.v
|
| 19 |
+
output strobe_o,
|
| 20 |
+
output [3:0] category
|
| 21 |
+
);
|
| 22 |
+
|
| 23 |
+
reg strobe_r=0;
|
| 24 |
+
reg [3:0] category_r;
|
| 25 |
+
always @(posedge clk) begin
|
| 26 |
+
strobe_r <= strobe;
|
| 27 |
+
// 0 not used
|
| 28 |
+
if (~status[2]) category_r <= 4'h1; // failed CRC
|
| 29 |
+
else if ( status[1:0] == 2'b01) category_r <= 4'h2; // ARP
|
| 30 |
+
else if (~status[3]) category_r <= 4'h3; // not MAC-addressed for us
|
| 31 |
+
else if (~status[4]) category_r <= 4'h4; // not IP
|
| 32 |
+
else if ( status[1:0] == 2'b00) category_r <= 4'h5; // other unrecognized
|
| 33 |
+
else if ( status[1:0] == 2'b10) category_r <= 4'h6; // ICMP
|
| 34 |
+
// 7 not used
|
| 35 |
+
else category_r <= {1'b1, status[7:5]}; // UDP, status[1:0] == 2'b11
|
| 36 |
+
end
|
| 37 |
+
|
| 38 |
+
assign strobe_o = strobe_r;
|
| 39 |
+
assign category = category_r;
|
| 40 |
+
|
| 41 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/pbuf_writer.v
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Takes results from scanner and forms the 9-bit output stream for
|
| 2 |
+
// the packet buffer, according to the plan shown in doc/memory.eps.
|
| 3 |
+
// Five-word "badge" written at the beginning of a packet:
|
| 4 |
+
// 1. Dummy, needed in case construct.v skips forward two
|
| 5 |
+
// 2. Length msb
|
| 6 |
+
// 3. Length lsb
|
| 7 |
+
// 4. Status
|
| 8 |
+
// 5. Reserved, currently zero
|
| 9 |
+
// .. where words 1 and 2 have the 9th bit set to mark start-of-frame.
|
| 10 |
+
// This structure must be kept consistent with decoder in construct.v.
|
| 11 |
+
//
|
| 12 |
+
// The datapath for the packet buffer data is reused to also produce
|
| 13 |
+
// a port that can write data to an Rx MAC. A 4 kByte buffer memory
|
| 14 |
+
// is the smallest that can guarantee holding two full packets, and
|
| 15 |
+
// we simply double buffer instead of trying something more complicated.
|
| 16 |
+
|
| 17 |
+
module pbuf_writer #(
|
| 18 |
+
parameter paw=11 // packet address width, 11 IRL, maybe less for simulations
|
| 19 |
+
) (
|
| 20 |
+
input clk,
|
| 21 |
+
// Simple flow of data from input state machine
|
| 22 |
+
// conforms to AXI-stream-lite, if I adjust the names?
|
| 23 |
+
input [7:0] data_in,
|
| 24 |
+
input data_s,
|
| 25 |
+
input data_f,
|
| 26 |
+
// Results of scanning process provided to us
|
| 27 |
+
input [10:0] pack_len,
|
| 28 |
+
input [7:0] status_vec,
|
| 29 |
+
input status_valid,
|
| 30 |
+
// port to DPRAM, write every cycle
|
| 31 |
+
output [8:0] mem_d,
|
| 32 |
+
output [paw-1:0] mem_a,
|
| 33 |
+
// port to Rx MAC memory
|
| 34 |
+
output [7:0] rx_mac_d,
|
| 35 |
+
output [11:0] rx_mac_a,
|
| 36 |
+
output rx_mac_wen,
|
| 37 |
+
// port to Rx MAC handshake
|
| 38 |
+
// Double buffering works as follows from the host point of view:
|
| 39 |
+
// * rx_mac_buf_status = [rx_mac_hbank_r, mac_bank]
|
| 40 |
+
// * rx_mac_hbank_r = points to the bank currently read (and blocked) by the host
|
| 41 |
+
// mac_bank = points to the bank the badger will write the next packet to (highest address bit)
|
| 42 |
+
// 1) badger toggles mac_bank once a packet has been completely received
|
| 43 |
+
// 2) The host knows new data is available when rx_mac_hbank_r == mac_bank
|
| 44 |
+
// 3) Host toggles rx_mac_hbank and is allowed to read the slot indexed by rx_mac_hbank_r in the next cycle
|
| 45 |
+
// 4) This allows badger to receive and write to the other slot, cycle continues from 1
|
| 46 |
+
input rx_mac_hbank,
|
| 47 |
+
output [1:0] rx_mac_buf_status,
|
| 48 |
+
// port to Rx MAC packet selector
|
| 49 |
+
input rx_mac_accept,
|
| 50 |
+
// Other
|
| 51 |
+
output [paw-1:0] gray_state, // Valid read pointer, Rx needs to know this
|
| 52 |
+
output badge_stb // debugging hook
|
| 53 |
+
);
|
| 54 |
+
|
| 55 |
+
// Possibly stupid waste of 8 FF, but makes development much easier
|
| 56 |
+
reg [7:0] status_r=0;
|
| 57 |
+
always @(posedge clk) if (status_valid) status_r <= status_vec;
|
| 58 |
+
|
| 59 |
+
// Synthesize address and data for output DPRAM.
|
| 60 |
+
// It's critical that we're able to fill in the badge once the packet has ended.
|
| 61 |
+
// See doc/memory.eps for a simplified description of what we're trying to accomplish.
|
| 62 |
+
reg [paw-1:0] fp=0; // unperturbed frame counter/pointer
|
| 63 |
+
reg [paw-1:0] fpp=0; // actual destination address
|
| 64 |
+
reg [paw-1:0] origin=0; // pointer to start of badge
|
| 65 |
+
reg [2:0] post_cnt=5;
|
| 66 |
+
reg [8:0] pxd=0; // data + sof marker in 9th bit
|
| 67 |
+
wire not_head = post_cnt==5;
|
| 68 |
+
reg badge_stb_r=0;
|
| 69 |
+
reg data_s_d=0;
|
| 70 |
+
wire trig = data_s & ~data_s_d;
|
| 71 |
+
always @(posedge clk) begin
|
| 72 |
+
data_s_d <= data_s;
|
| 73 |
+
// Setup counter to start writing the badge at the end of data
|
| 74 |
+
// Stagnate counter at 5, and if that's the case write data through
|
| 75 |
+
post_cnt <= data_f ? 3'd0 : not_head ? 3'd5 : post_cnt+1;
|
| 76 |
+
if (trig) origin <= fp;
|
| 77 |
+
case (post_cnt)
|
| 78 |
+
// 12 unused bits, will find customers later, including authentication
|
| 79 |
+
// Note that the 0 to 1 transition in bit 7 position between states 0 and 1
|
| 80 |
+
// is absolutely CRITICALLY IMPORTANT to let the reader find the beginning
|
| 81 |
+
// of the packet even when it occasionally skips reading a word, in the
|
| 82 |
+
// case where the reader (Tx side) clock is slower than this clock.
|
| 83 |
+
0: pxd <= {1'b1, 1'b0, 7'b0};
|
| 84 |
+
1: pxd <= {1'b1, 1'b1, pack_len[6:0]};
|
| 85 |
+
2: pxd <= {1'b0, 4'd0, pack_len[10:7]};
|
| 86 |
+
3: pxd <= {1'b0, status_r};
|
| 87 |
+
4: pxd <= {1'b0, 8'd0};
|
| 88 |
+
5: pxd <= {1'b0, data_in};
|
| 89 |
+
default: pxd <= 9'bx;
|
| 90 |
+
endcase
|
| 91 |
+
fp <= fp+1;
|
| 92 |
+
fpp <= data_s ? fp + 5 : not_head ? fp : origin + post_cnt;
|
| 93 |
+
badge_stb_r <= post_cnt!=0 && post_cnt!=5;
|
| 94 |
+
end
|
| 95 |
+
|
| 96 |
+
// Output ports
|
| 97 |
+
assign mem_a = fpp;
|
| 98 |
+
assign mem_d = pxd;
|
| 99 |
+
assign badge_stb = badge_stb_r;
|
| 100 |
+
|
| 101 |
+
// We need rx_mac_hbank in our own clk domain
|
| 102 |
+
// Better to pull this step up to rtefi_center?
|
| 103 |
+
wire rx_mac_hbank_r;
|
| 104 |
+
reg_tech_cdc rx_mac_hbank_cdc(.I(rx_mac_hbank), .C(clk), .O(rx_mac_hbank_r));
|
| 105 |
+
|
| 106 |
+
// MAC logic
|
| 107 |
+
reg [10:0] mac_a0=0;
|
| 108 |
+
reg mac_bank=0;
|
| 109 |
+
wire bank_ready = mac_bank != rx_mac_hbank_r;
|
| 110 |
+
assign rx_mac_buf_status = {rx_mac_hbank_r, mac_bank};
|
| 111 |
+
reg mac_save=0, mac_stopping=0;
|
| 112 |
+
reg mac_queue=0;
|
| 113 |
+
always @(posedge clk) begin
|
| 114 |
+
if (trig & bank_ready) mac_save <= 1;
|
| 115 |
+
if (trig) mac_a0 <= 4;
|
| 116 |
+
else if (post_cnt==1) mac_a0 <= 0;
|
| 117 |
+
else mac_a0 <= mac_a0 + 1;
|
| 118 |
+
mac_stopping <= post_cnt == 4;
|
| 119 |
+
if (mac_stopping) mac_save <= 0;
|
| 120 |
+
if ((post_cnt==1) & mac_save & rx_mac_accept) begin
|
| 121 |
+
// At his point we know we'll forward the packet to the host
|
| 122 |
+
mac_queue <= 1;
|
| 123 |
+
end
|
| 124 |
+
if (mac_stopping & mac_queue) begin
|
| 125 |
+
mac_bank <= ~mac_bank;
|
| 126 |
+
mac_queue <= 0;
|
| 127 |
+
end
|
| 128 |
+
end
|
| 129 |
+
assign rx_mac_d = pxd[7:0];
|
| 130 |
+
assign rx_mac_a = {mac_bank, mac_a0};
|
| 131 |
+
assign rx_mac_wen = mac_save;
|
| 132 |
+
|
| 133 |
+
// Convert to Gray code for Rx side, so Rx and Tx can be in different clock domains
|
| 134 |
+
wire [paw-1:0] fp_gray = fp ^ {1'b0, fp[paw-1:1]};
|
| 135 |
+
reg [paw-1:0] gray_state_r=0; always @(posedge clk) gray_state_r <= fp_gray;
|
| 136 |
+
assign gray_state = gray_state_r;
|
| 137 |
+
|
| 138 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/precog.v
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// A gap detector for timing transmissions from the MAC.
|
| 2 |
+
// The `scanner` module looks ahead for a suitable gap in the packet badger
|
| 3 |
+
// data stream. Once found it indicates to the MAC, downstream of the
|
| 4 |
+
// ring-buffer, that its TX - packet can now be multiplexed onto the stream.
|
| 5 |
+
|
| 6 |
+
module precog #(
|
| 7 |
+
// packet address width, 11 IRL
|
| 8 |
+
parameter PAW=11,
|
| 9 |
+
// latency from beginning of detected gap to `clear_to_send` going high
|
| 10 |
+
parameter LATENCY=11
|
| 11 |
+
) (
|
| 12 |
+
input clk,
|
| 13 |
+
// during a gap of N cycles, `scanner_busy` goes low for N cycles
|
| 14 |
+
input scanner_busy,
|
| 15 |
+
// Minimum width of the gap. tx_packet_width must be <= LATENCY - 2
|
| 16 |
+
input [PAW-1:0] tx_packet_width,
|
| 17 |
+
// pulse to latch `tx_packet_width` and start searching for a gap
|
| 18 |
+
input request_to_send,
|
| 19 |
+
// Rising edge: `LATENCY` cycles after the beginning of the detected gap
|
| 20 |
+
// Falling edge: `tx_packet_width` cycles after the rising edge
|
| 21 |
+
output reg clear_to_send
|
| 22 |
+
);
|
| 23 |
+
|
| 24 |
+
initial clear_to_send = 0;
|
| 25 |
+
reg [PAW-1:0] gap_width = 0;
|
| 26 |
+
reg [PAW-1:0] tx_packet_width_l = 0;
|
| 27 |
+
reg [ 11:0] delay_cnt = 0;
|
| 28 |
+
reg [ 1:0] state = 0;
|
| 29 |
+
wire is_gap = gap_width >= tx_packet_width_l;
|
| 30 |
+
localparam ST_WAIT_RTS = 0;
|
| 31 |
+
localparam ST_WAIT_GAP = 1;
|
| 32 |
+
localparam ST_WAIT_RISING = 2;
|
| 33 |
+
localparam ST_WAIT_FALLING = 3;
|
| 34 |
+
|
| 35 |
+
always @(posedge clk) begin
|
| 36 |
+
clear_to_send <= 0;
|
| 37 |
+
if (scanner_busy) gap_width <= 0;
|
| 38 |
+
else if (~(&gap_width)) gap_width <= gap_width + 1;
|
| 39 |
+
case (state)
|
| 40 |
+
ST_WAIT_RTS: begin
|
| 41 |
+
tx_packet_width_l <= tx_packet_width;
|
| 42 |
+
if (request_to_send)
|
| 43 |
+
state <= ST_WAIT_GAP;
|
| 44 |
+
end
|
| 45 |
+
|
| 46 |
+
ST_WAIT_GAP: begin
|
| 47 |
+
delay_cnt <= 0;
|
| 48 |
+
if (is_gap)
|
| 49 |
+
state <= ST_WAIT_RISING;
|
| 50 |
+
end
|
| 51 |
+
|
| 52 |
+
ST_WAIT_RISING: begin
|
| 53 |
+
delay_cnt <= delay_cnt + 1;
|
| 54 |
+
if (delay_cnt >= LATENCY - tx_packet_width_l - 2) begin
|
| 55 |
+
delay_cnt <= 0;
|
| 56 |
+
clear_to_send <= 1;
|
| 57 |
+
state <= ST_WAIT_FALLING;
|
| 58 |
+
end
|
| 59 |
+
end
|
| 60 |
+
|
| 61 |
+
ST_WAIT_FALLING: begin
|
| 62 |
+
delay_cnt <= delay_cnt + 1;
|
| 63 |
+
if (delay_cnt >= tx_packet_width_l - 1)
|
| 64 |
+
state <= ST_WAIT_RTS;
|
| 65 |
+
else
|
| 66 |
+
clear_to_send <= 1;
|
| 67 |
+
end
|
| 68 |
+
|
| 69 |
+
default: begin
|
| 70 |
+
state <= ST_WAIT_RTS;
|
| 71 |
+
gap_width <= 0;
|
| 72 |
+
delay_cnt <= 0;
|
| 73 |
+
end
|
| 74 |
+
endcase
|
| 75 |
+
end
|
| 76 |
+
|
| 77 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/rtefi_center.v
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Full RTEFI Rx/Tx pipeline
|
| 2 |
+
//
|
| 3 |
+
// Ports are abstract GMII (maybe should adjust their names?).
|
| 4 |
+
// Non-GMII hardware can and should add an adapter layer to get
|
| 5 |
+
// from GMII to RGMII or the MGT. Actual GMII hardware can just
|
| 6 |
+
// connect these ports to the physical pins.
|
| 7 |
+
//
|
| 8 |
+
// Up to seven clients, each handling a UDP port, attach here.
|
| 9 |
+
//
|
| 10 |
+
// This module instantiates a series of modules for the data path
|
| 11 |
+
// linking GMII Rx through to GMII Tx, shown in doc/rtefi.eps.
|
| 12 |
+
// The several steps have instance names starting with a through e
|
| 13 |
+
// (a_scan through e_crc).
|
| 14 |
+
//
|
| 15 |
+
module rtefi_center #(
|
| 16 |
+
parameter paw = 11, // packet (memory) address width, nominal 11
|
| 17 |
+
parameter n_lat = 3, // latency of client pipeline
|
| 18 |
+
parameter mac_aw = 10, // sets size (in 16-bit words) of DPRAM in Tx MAC
|
| 19 |
+
parameter handle_arp = 1,
|
| 20 |
+
parameter handle_icmp = 1,
|
| 21 |
+
// The following parameters set the synthesis-time default, but all
|
| 22 |
+
// can be overridden at run-time using the configuration port.
|
| 23 |
+
// UDP ports 0 through 7 represent the index given in udp_sel.
|
| 24 |
+
// While udp_port_cam.v is written parameterized, we limit it to
|
| 25 |
+
// three bits and 8 ports for timing reasons. Port 0 is internally
|
| 26 |
+
// implemented as echo; the rest will be user-defined via synthesis-time
|
| 27 |
+
// plug-ins. Generally the UDP port numbers should be "well known",
|
| 28 |
+
// but the case can be made to have them run-time override-able (without
|
| 29 |
+
// resynthesizing) to help cope with unexpected network issues.
|
| 30 |
+
// When a udp_port number is set to 0, that port is disabled.
|
| 31 |
+
parameter [31:0] ip = {8'd192, 8'd168, 8'd7, 8'd4}, // 192.168.7.4
|
| 32 |
+
parameter [47:0] mac = 48'h12555500012d,
|
| 33 |
+
parameter udp_port0 = 7,
|
| 34 |
+
parameter udp_port1 = 801,
|
| 35 |
+
parameter udp_port2 = 802,
|
| 36 |
+
parameter udp_port3 = 803,
|
| 37 |
+
parameter udp_port4 = 0,
|
| 38 |
+
parameter udp_port5 = 0,
|
| 39 |
+
parameter udp_port6 = 0,
|
| 40 |
+
parameter udp_port7 = 0
|
| 41 |
+
) (
|
| 42 |
+
// GMII Input (Rx)
|
| 43 |
+
input rx_clk,
|
| 44 |
+
input [7:0] rxd,
|
| 45 |
+
input rx_dv,
|
| 46 |
+
input rx_er,
|
| 47 |
+
// GMII Output (Tx)
|
| 48 |
+
input tx_clk,
|
| 49 |
+
output [7:0] txd,
|
| 50 |
+
output tx_en,
|
| 51 |
+
// Configuration
|
| 52 |
+
// When changing configuration (like IP) at run time with these ports,
|
| 53 |
+
// it's recommended to turn off enable_rx during that process.
|
| 54 |
+
input enable_rx,
|
| 55 |
+
input config_clk,
|
| 56 |
+
input [3:0] config_a,
|
| 57 |
+
input [7:0] config_d,
|
| 58 |
+
input config_s, // MAC/IP address write
|
| 59 |
+
input config_p, // UDP port number write
|
| 60 |
+
// Host side of Tx MAC
|
| 61 |
+
// connect the 2 below to an external 16 bit dual port ram
|
| 62 |
+
output [mac_aw - 1: 0] host_raddr,
|
| 63 |
+
input [15:0] host_rdata,
|
| 64 |
+
// address where we should start transmitting from
|
| 65 |
+
input [mac_aw - 1: 0] buf_start_addr,
|
| 66 |
+
// set start to trigger transmission, wait for done, reset start
|
| 67 |
+
input tx_mac_start,
|
| 68 |
+
output tx_mac_done,
|
| 69 |
+
// As documented in doc/clients.eps
|
| 70 |
+
output [10:0] len_c,
|
| 71 |
+
output [6:0] raw_l,
|
| 72 |
+
output [6:0] raw_s,
|
| 73 |
+
output [7:0] idata,
|
| 74 |
+
input [7*8-1:0] mux_data_in, // collection of odata
|
| 75 |
+
// port to Rx MAC memory
|
| 76 |
+
output [7:0] rx_mac_d,
|
| 77 |
+
output [11:0] rx_mac_a,
|
| 78 |
+
output rx_mac_wen,
|
| 79 |
+
// port to Rx MAC handshake
|
| 80 |
+
input rx_mac_hbank,
|
| 81 |
+
output [1:0] rx_mac_buf_status,
|
| 82 |
+
// port to Rx MAC packet selector
|
| 83 |
+
input rx_mac_accept,
|
| 84 |
+
output [7:0] rx_mac_status_d,
|
| 85 |
+
output rx_mac_status_s,
|
| 86 |
+
// Debugging
|
| 87 |
+
output ibadge_stb,
|
| 88 |
+
output [7:0] ibadge_data,
|
| 89 |
+
output obadge_stb,
|
| 90 |
+
output [7:0] obadge_data,
|
| 91 |
+
output xdomain_fault,
|
| 92 |
+
// Dumb stuff to get LEDs blinking
|
| 93 |
+
output [3:0] scanner_debug,
|
| 94 |
+
output rx_mon,
|
| 95 |
+
output tx_mon,
|
| 96 |
+
// Simulation-only
|
| 97 |
+
output in_use
|
| 98 |
+
);
|
| 99 |
+
|
| 100 |
+
// Overhead: make sure the tools can create an IOB on all GMII inputs
|
| 101 |
+
reg [7:0] eth_in_r=0;
|
| 102 |
+
reg eth_in_s_r=0, eth_in_e_r=0;
|
| 103 |
+
always @(posedge rx_clk) begin
|
| 104 |
+
eth_in_r <= rxd;
|
| 105 |
+
eth_in_s_r <= rx_dv;
|
| 106 |
+
eth_in_e_r <= rx_er;
|
| 107 |
+
end
|
| 108 |
+
|
| 109 |
+
// First real step: scan the input packet
|
| 110 |
+
wire [3:0] ip_a; reg [7:0] ip_d=0; // MAC/IP config, Rx side
|
| 111 |
+
wire [3:0] pno_a; reg [7:0] pno_d=0; // UDP port numbers
|
| 112 |
+
wire [7:0] sdata;
|
| 113 |
+
wire scanner_busy;
|
| 114 |
+
wire sdata_s, sdata_l;
|
| 115 |
+
wire [10:0] pack_len;
|
| 116 |
+
wire [7:0] status_vec; wire status_valid;
|
| 117 |
+
scanner #(.handle_arp(handle_arp), .handle_icmp(handle_icmp)) a_scan(
|
| 118 |
+
.clk(rx_clk),
|
| 119 |
+
.eth_in(eth_in_r), .eth_in_s(eth_in_s_r), .eth_in_e(eth_in_e_r),
|
| 120 |
+
.enable_rx(enable_rx),
|
| 121 |
+
.ip_a(ip_a), .ip_d(ip_d),
|
| 122 |
+
.pno_a(pno_a), .pno_d(pno_d),
|
| 123 |
+
.busy(scanner_busy), .debug(scanner_debug),
|
| 124 |
+
.odata(sdata), .odata_s(sdata_s), .odata_f(sdata_l),
|
| 125 |
+
.pack_len(pack_len), .status_vec(status_vec), .status_valid(status_valid)
|
| 126 |
+
);
|
| 127 |
+
assign rx_mac_status_d = status_vec;
|
| 128 |
+
assign rx_mac_status_s = status_valid;
|
| 129 |
+
`ifdef SIMULATE
|
| 130 |
+
// always @(negedge rx_clk) if (status_valid) $display("Rx scanner status %x", status_vec);
|
| 131 |
+
`endif
|
| 132 |
+
|
| 133 |
+
// Second step: create data flow to DPRAM
|
| 134 |
+
wire [paw-1:0] pbuf_a_rx, gray_state;
|
| 135 |
+
wire [8:0] pbuf_din;
|
| 136 |
+
pbuf_writer #(.paw(paw)) b_write(.clk(rx_clk),
|
| 137 |
+
.data_in(sdata), .data_s(sdata_s), .data_f(sdata_l),
|
| 138 |
+
.pack_len(pack_len), .status_vec(status_vec), .status_valid(status_valid),
|
| 139 |
+
.mem_a(pbuf_a_rx), .mem_d(pbuf_din),
|
| 140 |
+
.rx_mac_d(rx_mac_d), .rx_mac_a(rx_mac_a), .rx_mac_wen(rx_mac_wen),
|
| 141 |
+
.rx_mac_hbank(rx_mac_hbank), .rx_mac_buf_status(rx_mac_buf_status),
|
| 142 |
+
.rx_mac_accept(rx_mac_accept),
|
| 143 |
+
.gray_state(gray_state),
|
| 144 |
+
.badge_stb(ibadge_stb)
|
| 145 |
+
);
|
| 146 |
+
assign ibadge_data = pbuf_din[7:0];
|
| 147 |
+
|
| 148 |
+
// 1 MTU DPRAM; note the ninth bit used to mark Start of Frame.
|
| 149 |
+
// Also note the lack of a write-enable; just write every cycle.
|
| 150 |
+
// I hate jumbo frames. Expect paw=11, so memory is big enough to hold 1500 MTU.
|
| 151 |
+
reg [8:0] pbuf[0:(1<<paw)-1];
|
| 152 |
+
reg [8:0] pbuf_out=0;
|
| 153 |
+
wire [paw-1:0] mem_a2; // see below
|
| 154 |
+
always @(posedge rx_clk) pbuf[pbuf_a_rx] <= pbuf_din;
|
| 155 |
+
always @(posedge tx_clk) pbuf_out <= pbuf[mem_a2];
|
| 156 |
+
integer jx;
|
| 157 |
+
initial for (jx=0; jx<(1<<paw); jx=jx+1) pbuf[jx]=0;
|
| 158 |
+
|
| 159 |
+
// Third step: sift through that packet's data to
|
| 160 |
+
// synthesize the reply packet's header
|
| 161 |
+
wire [3:0] ip_mem_a_tx; reg[7:0] ip_mem_d_tx=0; // MAC/IP config, Tx side
|
| 162 |
+
// Signals sent from construct to xformer
|
| 163 |
+
wire [5:0] pc;
|
| 164 |
+
wire [1:0] category;
|
| 165 |
+
wire [2:0] udp_sel;
|
| 166 |
+
wire [7:0] eth_data_out;
|
| 167 |
+
wire eth_strobe_short, eth_strobe_long;
|
| 168 |
+
localparam p_offset=480; // see notes in construct.v
|
| 169 |
+
construct #(.paw(paw), .p_offset(p_offset)) c_construct(.clk(tx_clk),
|
| 170 |
+
.gray_state(gray_state),
|
| 171 |
+
.ip_a(ip_mem_a_tx), .ip_d(ip_mem_d_tx),
|
| 172 |
+
.addr(mem_a2), .pbuf_out(pbuf_out),
|
| 173 |
+
.pc(pc), .category(category), .udp_sel(udp_sel),
|
| 174 |
+
.badge_stb(obadge_stb), .badge_data(obadge_data),
|
| 175 |
+
.xdomain_fault(xdomain_fault),
|
| 176 |
+
.eth_data_out(eth_data_out), .eth_strobe_short(eth_strobe_short), .eth_strobe_long(eth_strobe_long)
|
| 177 |
+
);
|
| 178 |
+
|
| 179 |
+
// Data multiplexer
|
| 180 |
+
wire xraw_s, xraw_l; wire [7:0] raw_d; // Output, still needs CRC
|
| 181 |
+
xformer #(.n_lat(n_lat), .handle_icmp(handle_icmp)) d_xform(.clk(tx_clk),
|
| 182 |
+
.pc(pc), .category(category), .udp_sel(udp_sel),
|
| 183 |
+
.idata(eth_data_out), .eth_strobe_short(eth_strobe_short), .eth_strobe_long(eth_strobe_long),
|
| 184 |
+
.len_c(len_c),
|
| 185 |
+
.raw_l(raw_l), .raw_s(raw_s),
|
| 186 |
+
.mux_data_in(mux_data_in),
|
| 187 |
+
.odata(raw_d), .ostrobe_s(xraw_s), .ostrobe_l(xraw_l)
|
| 188 |
+
);
|
| 189 |
+
assign idata = eth_data_out;
|
| 190 |
+
|
| 191 |
+
// Tx MAC
|
| 192 |
+
// Disable by setting mac_aw=1
|
| 193 |
+
// precog_latency is kind of important;
|
| 194 |
+
// check resulting interpacket gap in simulations
|
| 195 |
+
localparam precog_latency = (1<<paw) - p_offset + 4 + n_lat;
|
| 196 |
+
wire [7:0] tx_mac_data;
|
| 197 |
+
wire tx_mac_strobe_s, tx_mac_strobe_l;
|
| 198 |
+
generate if (mac_aw > 1) begin : mac_b
|
| 199 |
+
mac_subset #(
|
| 200 |
+
.mac_aw(mac_aw),
|
| 201 |
+
.latency(precog_latency)
|
| 202 |
+
) txmac (
|
| 203 |
+
.host_raddr(host_raddr),
|
| 204 |
+
.host_rdata(host_rdata),
|
| 205 |
+
.buf_start_addr(buf_start_addr),
|
| 206 |
+
.tx_mac_start(tx_mac_start),
|
| 207 |
+
.tx_mac_done(tx_mac_done),
|
| 208 |
+
.scanner_busy(scanner_busy),
|
| 209 |
+
.tx_clk(tx_clk),
|
| 210 |
+
.mac_data(tx_mac_data),
|
| 211 |
+
.strobe_s(tx_mac_strobe_s),
|
| 212 |
+
.strobe_l(tx_mac_strobe_l)
|
| 213 |
+
);
|
| 214 |
+
end else begin : no_mac_b
|
| 215 |
+
assign host_raddr = 0;
|
| 216 |
+
assign tx_mac_strobe_s = 0;
|
| 217 |
+
assign tx_mac_strobe_l = 0;
|
| 218 |
+
assign tx_mac_data = 0;
|
| 219 |
+
assign tx_mac_done = 0;
|
| 220 |
+
end endgenerate
|
| 221 |
+
|
| 222 |
+
// Slide data from Tx MAC in here
|
| 223 |
+
// XXX no cross-checking that the MAC is avoiding collisions
|
| 224 |
+
// using precog the way it's supposed to.
|
| 225 |
+
wire xraw2_s = xraw_s | tx_mac_strobe_s;
|
| 226 |
+
wire xraw2_l = xraw_l | tx_mac_strobe_l;
|
| 227 |
+
wire [7:0] raw2_d = tx_mac_strobe_s ? tx_mac_data : raw_d;
|
| 228 |
+
|
| 229 |
+
// Finally, add Ethernet CRC and GMII preamble
|
| 230 |
+
wire opack_s; wire [7:0] opack_d;
|
| 231 |
+
ethernet_crc_add e_crc(.clk(tx_clk),
|
| 232 |
+
.raw_s(xraw2_s), .raw_l(xraw2_l), .raw_d(raw2_d),
|
| 233 |
+
.opack_s(opack_s), .opack_d(opack_d)
|
| 234 |
+
);
|
| 235 |
+
|
| 236 |
+
// Make sure these outputs can be put into an IOB
|
| 237 |
+
reg [7:0] eth_out_r=0;
|
| 238 |
+
reg eth_out_s_r=0;
|
| 239 |
+
always @(posedge tx_clk) begin
|
| 240 |
+
eth_out_r <= opack_d;
|
| 241 |
+
eth_out_s_r <= opack_s;
|
| 242 |
+
end
|
| 243 |
+
assign txd = eth_out_r;
|
| 244 |
+
assign tx_en = eth_out_s_r;
|
| 245 |
+
|
| 246 |
+
// Has to be distinct from the IOBs
|
| 247 |
+
assign rx_mon = eth_in_s_r;
|
| 248 |
+
assign tx_mon = opack_s;
|
| 249 |
+
|
| 250 |
+
// Hook for testing; not intended to be connected in hardware
|
| 251 |
+
reg [paw-1:0] in_use_timer=0;
|
| 252 |
+
assign in_use = |in_use_timer;
|
| 253 |
+
always @(posedge rx_clk) begin
|
| 254 |
+
if (in_use) in_use_timer <= in_use_timer - 1;
|
| 255 |
+
if (rx_mon) in_use_timer <= {paw{1'b1}};
|
| 256 |
+
end
|
| 257 |
+
|
| 258 |
+
// Memory for MAC/IP addresses
|
| 259 |
+
reg [7:0] ip_mem[0:15];
|
| 260 |
+
always @(posedge config_clk) if (config_s) ip_mem[config_a] <= config_d;
|
| 261 |
+
always @(posedge rx_clk) ip_d <= ip_mem[ip_a];
|
| 262 |
+
always @(posedge tx_clk) ip_mem_d_tx <= ip_mem[ip_mem_a_tx];
|
| 263 |
+
initial begin
|
| 264 |
+
// Matches packets in at least arp3.dat, icmp3.dat, udp3.dat.
|
| 265 |
+
ip_mem[0] = mac[47:40]; // Start of MAC
|
| 266 |
+
ip_mem[1] = mac[39:32];
|
| 267 |
+
ip_mem[2] = mac[31:24];
|
| 268 |
+
ip_mem[3] = mac[23:16];
|
| 269 |
+
ip_mem[4] = mac[15:8];
|
| 270 |
+
ip_mem[5] = mac[7:0]; // End of MAC
|
| 271 |
+
ip_mem[6] = ip[31:24]; // Start of IP
|
| 272 |
+
ip_mem[7] = ip[23:16];
|
| 273 |
+
ip_mem[8] = ip[15:8];
|
| 274 |
+
ip_mem[9] = ip[7:0]; // End of IP
|
| 275 |
+
end
|
| 276 |
+
|
| 277 |
+
// Memory for UDP port numbers
|
| 278 |
+
reg [7:0] pno_mem[0:15];
|
| 279 |
+
always @(posedge config_clk) if (config_p) pno_mem[config_a] <= config_d;
|
| 280 |
+
always @(posedge rx_clk) pno_d <= pno_mem[pno_a];
|
| 281 |
+
initial begin
|
| 282 |
+
pno_mem[0] = udp_port0[15:8];
|
| 283 |
+
pno_mem[1] = udp_port0[7:0];
|
| 284 |
+
pno_mem[2] = udp_port1[15:8];
|
| 285 |
+
pno_mem[3] = udp_port1[7:0];
|
| 286 |
+
pno_mem[4] = udp_port2[15:8];
|
| 287 |
+
pno_mem[5] = udp_port2[7:0];
|
| 288 |
+
pno_mem[6] = udp_port3[15:8];
|
| 289 |
+
pno_mem[7] = udp_port3[7:0];
|
| 290 |
+
pno_mem[8] = udp_port4[15:8];
|
| 291 |
+
pno_mem[9] = udp_port4[7:0];
|
| 292 |
+
pno_mem[10] = udp_port5[15:8];
|
| 293 |
+
pno_mem[11] = udp_port5[7:0];
|
| 294 |
+
pno_mem[12] = udp_port6[15:8];
|
| 295 |
+
pno_mem[13] = udp_port6[7:0];
|
| 296 |
+
pno_mem[14] = udp_port7[15:8];
|
| 297 |
+
pno_mem[15] = udp_port7[7:0];
|
| 298 |
+
end
|
| 299 |
+
|
| 300 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/rtefi_notes.txt
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Real-Time Ethernet Fabric Infrastructure (building on PSPEPS experience)
|
| 2 |
+
(work-in-progress)
|
| 3 |
+
|
| 4 |
+
Also see rtefi.eps
|
| 5 |
+
|
| 6 |
+
Keep core success of PSPEPS that it can support self-throttled full-rate
|
| 7 |
+
communications to unbuffered clients. Supporting UDP rather than raw
|
| 8 |
+
Ethernet is (still) worth the effort in order to align with the security
|
| 9 |
+
model of typical host computers; an application doesn't need root privileges
|
| 10 |
+
to communicate over UDP.
|
| 11 |
+
|
| 12 |
+
Hardware support limited to IP, ARP, ICMP echo, UDP. TCP support (if any)
|
| 13 |
+
would be relegated to the soft-core. IPv4 only, no IP options or
|
| 14 |
+
fragmentation. Supporting jumbo packets is easy in theory, but balloons the
|
| 15 |
+
latency and amount of storage needed; just don't do it.
|
| 16 |
+
|
| 17 |
+
A major defect in PSPEPS was the side-channel handling of source IP and MAC,
|
| 18 |
+
which was easily confused when handling communication from multiple hosts.
|
| 19 |
+
That info is correctly handled per-packet in RTEFI.
|
| 20 |
+
|
| 21 |
+
Even clients that have to buffer their data need to be shoehorned into the
|
| 22 |
+
unbuffered paradigm. Expect this will happen by making them respond to each
|
| 23 |
+
input packet with a status message that includes their (possibly incomplete)
|
| 24 |
+
output buffer. Known possible sub-clients include flash programming,
|
| 25 |
+
microcontroller bridge, and JTAG. Those sub-clients could share (time-slice
|
| 26 |
+
access) their input and output buffers. Work on such clients has not started.
|
| 27 |
+
|
| 28 |
+
A common packet structure for the buffered clients can include at least one
|
| 29 |
+
nonce, a flag for reply-buffer complete, and a time estimate for when that
|
| 30 |
+
buffer will be complete. Plus optional authentication components, see below.
|
| 31 |
+
|
| 32 |
+
We hope eventually to include PTP/White Rabbit IEEE-1588 capability somewhere,
|
| 33 |
+
maybe with the assistance of a soft-core.
|
| 34 |
+
|
| 35 |
+
The input scanner transcribes packets with a fixed latency of about 20 cycles.
|
| 36 |
+
Status bits written to badge include, among other things, a check that the
|
| 37 |
+
UDP payload length is consistent with the actual packet length; a packet that
|
| 38 |
+
fails that test is considered not UDP.
|
| 39 |
+
|
| 40 |
+
The badge added to packet by the input scanner is necessarily less than 12
|
| 41 |
+
octets, the minimum IFG. Actually one less than that, due to the potential
|
| 42 |
+
Tx/Rx 100ppm clock mismatch. The actual length now is five octets.
|
| 43 |
+
|
| 44 |
+
The mem_gateway client could eventually have two UDP port numbers, one with
|
| 45 |
+
and one without authentication.
|
| 46 |
+
|
| 47 |
+
Output signature insertion must have a fixed latency, maybe around 16 cycles.
|
| 48 |
+
This contrasts with the one-cycle latency of CRC32 insertion.
|
| 49 |
+
|
| 50 |
+
Plan to write a self-diagnostic client, capable of reporting things like packet
|
| 51 |
+
counts, byte counts, error counts, Rx/Tx frequency ratio, and which hosts
|
| 52 |
+
are communicating. Of course it will be optional, but attempt to make it
|
| 53 |
+
small and non-intrusive enough that it will practically be kept in most builds.
|
| 54 |
+
It's an interesting question whether reports should be public or require
|
| 55 |
+
authentication. Not sure if it is better handled as as a buffered or
|
| 56 |
+
unbuffered client.
|
| 57 |
+
|
| 58 |
+
Rx MAC for soft-core should be run-time configurable by the soft-core; nominal
|
| 59 |
+
is to accept all packets with our dest MAC and IP, but not handled by hardware
|
| 60 |
+
clients. It will inherently receive packets with IP options or fragmentation
|
| 61 |
+
set. Include promiscuous mode option.
|
| 62 |
+
|
| 63 |
+
Precog (precognition) module leverages the 1 MTU shift register to look ahead
|
| 64 |
+
for a prescribed gap in the input. That will become an available slot in the
|
| 65 |
+
Tx channel into which the output buffer of the soft-core MAC can be inserted.
|
| 66 |
+
|
| 67 |
+
PSPEPS claimed to fit in 1000 LUTs minimum; this base structure hasn't
|
| 68 |
+
changed that much. Prototyping indicates authentication will likely add over
|
| 69 |
+
1000 more LUT. We could still come in at under 10% of a 7A35T.
|
| 70 |
+
|
| 71 |
+
Minimum DPRAM usage is one, without authentication or any buffered clients.
|
| 72 |
+
Add two for authentication key memory, two for buffered clients, two for a
|
| 73 |
+
soft-core MAC, and two typical overhead internal to mem_gateway (config_romx
|
| 74 |
+
and mirror), total could reach nine. All DPRAM instances should be useful
|
| 75 |
+
at 2K x 8, the minimum size in 7-series Xilinx chips.
|
| 76 |
+
|
| 77 |
+
UDP checksums are always disabled now. We could also provide the option for
|
| 78 |
+
a client to fake its checksum. A true checksum is not possible for causality
|
| 79 |
+
reasons.
|
| 80 |
+
|
| 81 |
+
Flash-program and JTAG buffered sub-clients will demand authentication.
|
| 82 |
+
|
| 83 |
+
People do ask about DHCP. This is likely a job for the soft-core.
|
| 84 |
+
|
| 85 |
+
UDP echo on port 7 is included in the baseline, no netlist overhead, but
|
| 86 |
+
can be disabled. No ICMP port unreachable responses are ever generated
|
| 87 |
+
(unless by some future soft core and its software). At some point we need
|
| 88 |
+
to probe/fingerprint this code with nmap, zmap, arp-scan, p0f, prads, others.
|
| 89 |
+
|
| 90 |
+
For maximum clarity and applicability, the implementation is (and needs
|
| 91 |
+
to be kept) 100% portable Verilog, properly testable with both Icarus and
|
| 92 |
+
Verilator. Some of that Verilog may be machine-generated by open-source
|
| 93 |
+
tools.
|
| 94 |
+
|
| 95 |
+
LBNL think tank props: Larry Doolittle, Vamsi Vytla, Eric Norum, Gang Huang
|
BerkeleyLab_Bedrock/badger/rtefi_preblob.v
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// rtefi_blob.v is normally a preprocessed version of rtefi_preblob.v with
|
| 2 |
+
// definitions from the include file expressed/expanded. That include file
|
| 3 |
+
// is itself machine-generated based on the desired clients.
|
| 4 |
+
//
|
| 5 |
+
// TL;DR: if this file is named rtefi_blob.v, it's probably a mistake to
|
| 6 |
+
// hand-edit it!
|
| 7 |
+
//
|
| 8 |
+
`include "rtefi_preblob.vh"
|
| 9 |
+
module rtefi_blob #(
|
| 10 |
+
parameter paw = 11, // packet (memory) address width, nominal 11
|
| 11 |
+
parameter n_lat = 8, // latency of client pipeline
|
| 12 |
+
parameter mac_aw = 10, // sets size (in 16-bit words) of DPRAM in Tx MAC
|
| 13 |
+
// See comments in rtefi_center.v
|
| 14 |
+
parameter [31:0] ip = {8'd192, 8'd168, 8'd7, 8'd4}, // 192.168.7.4
|
| 15 |
+
parameter [47:0] mac = 48'h12555500012d,
|
| 16 |
+
`BLOB_PARAMS
|
| 17 |
+
parameter udp_port0 = 7,
|
| 18 |
+
parameter udp_port1 = 801,
|
| 19 |
+
parameter udp_port2 = 802,
|
| 20 |
+
parameter udp_port3 = 803,
|
| 21 |
+
parameter udp_port4 = 804,
|
| 22 |
+
parameter udp_port5 = 0,
|
| 23 |
+
parameter udp_port6 = 0,
|
| 24 |
+
parameter udp_port7 = 0
|
| 25 |
+
) (
|
| 26 |
+
// GMII Input (Rx)
|
| 27 |
+
input rx_clk,
|
| 28 |
+
input [7:0] rxd,
|
| 29 |
+
input rx_dv,
|
| 30 |
+
input rx_er,
|
| 31 |
+
// GMII Output (Tx)
|
| 32 |
+
input tx_clk,
|
| 33 |
+
output [7:0] txd,
|
| 34 |
+
output tx_en,
|
| 35 |
+
output tx_er,
|
| 36 |
+
// Configuration
|
| 37 |
+
input enable_rx,
|
| 38 |
+
input config_clk,
|
| 39 |
+
input [3:0] config_a,
|
| 40 |
+
input [7:0] config_d,
|
| 41 |
+
input config_s, // MAC/IP address write
|
| 42 |
+
input config_p, // UDP port number write
|
| 43 |
+
// Host side of Tx MAC
|
| 44 |
+
// connect the 2 below to an external 16 bit dual port ram
|
| 45 |
+
output [mac_aw - 1: 0] host_raddr,
|
| 46 |
+
input [15:0] host_rdata,
|
| 47 |
+
// address where we should start transmitting from
|
| 48 |
+
input [mac_aw - 1: 0] buf_start_addr,
|
| 49 |
+
// set start to trigger transmission, wait for done, reset start
|
| 50 |
+
input tx_mac_start,
|
| 51 |
+
output tx_mac_done,
|
| 52 |
+
// port to Rx MAC memory
|
| 53 |
+
output [7:0] rx_mac_d,
|
| 54 |
+
output [11:0] rx_mac_a,
|
| 55 |
+
output rx_mac_wen,
|
| 56 |
+
// port to Rx MAC handshake
|
| 57 |
+
input rx_mac_hbank,
|
| 58 |
+
output [1:0] rx_mac_buf_status,
|
| 59 |
+
// port to Rx MAC packet selector
|
| 60 |
+
output [7:0] rx_mac_status_d,
|
| 61 |
+
output rx_mac_status_s,
|
| 62 |
+
input rx_mac_accept,
|
| 63 |
+
// Debugging
|
| 64 |
+
output [3:0] scanner_debug,
|
| 65 |
+
output ibadge_stb,
|
| 66 |
+
output [7:0] ibadge_data,
|
| 67 |
+
output obadge_stb,
|
| 68 |
+
output [7:0] obadge_data,
|
| 69 |
+
output xdomain_fault,
|
| 70 |
+
// Pass-through to user modules
|
| 71 |
+
`BLOB_PORTS
|
| 72 |
+
// Dumb stuff to get LEDs blinking
|
| 73 |
+
output rx_mon,
|
| 74 |
+
output tx_mon,
|
| 75 |
+
// Simulation-only
|
| 76 |
+
output in_use
|
| 77 |
+
);
|
| 78 |
+
|
| 79 |
+
wire [10:0] len_c;
|
| 80 |
+
wire [6:0] raw_l;
|
| 81 |
+
wire [6:0] raw_s;
|
| 82 |
+
wire [7:0] idata;
|
| 83 |
+
wire [7*8-1:0] mux_data_in;
|
| 84 |
+
|
| 85 |
+
rtefi_center #(
|
| 86 |
+
.ip(ip), .mac(mac), .paw(paw), .n_lat(n_lat),
|
| 87 |
+
.mac_aw(mac_aw),
|
| 88 |
+
.udp_port0(udp_port0),
|
| 89 |
+
.udp_port1(udp_port1),
|
| 90 |
+
.udp_port2(udp_port2),
|
| 91 |
+
.udp_port3(udp_port3),
|
| 92 |
+
.udp_port4(udp_port4),
|
| 93 |
+
.udp_port5(udp_port5),
|
| 94 |
+
.udp_port6(udp_port6),
|
| 95 |
+
.udp_port7(udp_port7)
|
| 96 |
+
) center(
|
| 97 |
+
.rx_clk(rx_clk), .rxd(rxd),
|
| 98 |
+
.rx_dv(rx_dv), .rx_er(rx_er),
|
| 99 |
+
.tx_clk(tx_clk) , .txd(txd),
|
| 100 |
+
.tx_en(tx_en),
|
| 101 |
+
.enable_rx(enable_rx),
|
| 102 |
+
.config_clk(config_clk), .config_s(config_s), .config_p(config_p),
|
| 103 |
+
.config_a(config_a), .config_d(config_d),
|
| 104 |
+
.len_c(len_c), .raw_l(raw_l), .raw_s(raw_s),
|
| 105 |
+
.idata(idata), .mux_data_in(mux_data_in),
|
| 106 |
+
.host_raddr(host_raddr),
|
| 107 |
+
.host_rdata(host_rdata),
|
| 108 |
+
.buf_start_addr(buf_start_addr),
|
| 109 |
+
.tx_mac_start(tx_mac_start),
|
| 110 |
+
.tx_mac_done(tx_mac_done),
|
| 111 |
+
.rx_mac_d(rx_mac_d), .rx_mac_a(rx_mac_a), .rx_mac_wen(rx_mac_wen),
|
| 112 |
+
.rx_mac_hbank(rx_mac_hbank), .rx_mac_buf_status(rx_mac_buf_status),
|
| 113 |
+
.rx_mac_accept(rx_mac_accept),
|
| 114 |
+
.rx_mac_status_d(rx_mac_status_d), .rx_mac_status_s(rx_mac_status_s),
|
| 115 |
+
.scanner_debug(scanner_debug),
|
| 116 |
+
.ibadge_stb(ibadge_stb), .ibadge_data(ibadge_data),
|
| 117 |
+
.obadge_stb(obadge_stb), .obadge_data(obadge_data),
|
| 118 |
+
.xdomain_fault(xdomain_fault),
|
| 119 |
+
.rx_mon(rx_mon), .tx_mon(tx_mon), .in_use(in_use)
|
| 120 |
+
);
|
| 121 |
+
|
| 122 |
+
wire clk = tx_clk;
|
| 123 |
+
wire [7:0] odata_p7, odata_p6, odata_p5, odata_p4, odata_p3, odata_p2, odata_p1;
|
| 124 |
+
assign mux_data_in = {odata_p7, odata_p6, odata_p5, odata_p4, odata_p3, odata_p2, odata_p1};
|
| 125 |
+
assign tx_er = 1'b0;
|
| 126 |
+
|
| 127 |
+
`BLOB_INSTANCES
|
| 128 |
+
|
| 129 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/scanner.v
ADDED
|
@@ -0,0 +1,526 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// scans input packet
|
| 2 |
+
|
| 3 |
+
// status_vec key:
|
| 4 |
+
// assign status_vec = {port_p, pass_ip, pass_ethmac, crc_zero, category};
|
| 5 |
+
// bit 0-1 category: 3=UDP, 2=ICMP, 1=ARP, 0=other
|
| 6 |
+
// bit 2 CRC32 passed
|
| 7 |
+
// bit 3 Destination MAC matched our configuration
|
| 8 |
+
// bit 4 valid IP packet of some kind
|
| 9 |
+
// bit 5-7 UDP virtual port number, output of CAM
|
| 10 |
+
|
| 11 |
+
// I haven't yet started trying to handle authentication here.
|
| 12 |
+
// That can wait; we have the architecture ready.
|
| 13 |
+
|
| 14 |
+
// This is a relatively long file, but it helps that it is broken down
|
| 15 |
+
// into smaller modules:
|
| 16 |
+
// scanner top level, see doc/rtefi.eps
|
| 17 |
+
// - arp_patt
|
| 18 |
+
// - ip_patt
|
| 19 |
+
// - icmp_patt
|
| 20 |
+
// - udp_patt
|
| 21 |
+
// The four submodules have relatively consistent ports and semantics.
|
| 22 |
+
|
| 23 |
+
module scanner (
|
| 24 |
+
input clk, // timespec 6.8 ns
|
| 25 |
+
input [7:0] eth_in,
|
| 26 |
+
input eth_in_s,
|
| 27 |
+
input eth_in_e, // error flag from PHY
|
| 28 |
+
// PSPEPS didn't do anything with eth_in_e, which is certainly
|
| 29 |
+
// a mistake, but did work in practice. Ditto for this version,
|
| 30 |
+
// and it's proven to be very robust. Presumably the 32-bit CRC
|
| 31 |
+
// makes the RX_ER bit effectively redundant?
|
| 32 |
+
//
|
| 33 |
+
// New port: async input to allow packet reception
|
| 34 |
+
// Lets someone turn off the Ethernet subsystem during maintenance,
|
| 35 |
+
// e.g., changing IP address.
|
| 36 |
+
input enable_rx,
|
| 37 |
+
// port to MAC/IP config, single-cycle latency
|
| 38 |
+
output [3:0] ip_a,
|
| 39 |
+
input [7:0] ip_d,
|
| 40 |
+
// port to UDP port number config memory, single-cycle latency
|
| 41 |
+
output [3:0] pno_a,
|
| 42 |
+
input [7:0] pno_d,
|
| 43 |
+
// Access to a single-cycle-latency RAM holding keys and masks,
|
| 44 |
+
// necessarily also in the Rx clock domain.
|
| 45 |
+
// output [9:0] key_addr,
|
| 46 |
+
// input [15:0] key_data,
|
| 47 |
+
//
|
| 48 |
+
// Two-bit summary info available to precog
|
| 49 |
+
// For a kept packet, busy has the full width of odata_s,
|
| 50 |
+
// but is delayed one cycle. Non-keep packets can have the busy
|
| 51 |
+
// line de-asserted as soon as the dropping condition is detected.
|
| 52 |
+
// When an incoming packet is categorized as causing a response,
|
| 53 |
+
// the keep line is asserted one cycle before busy falls.
|
| 54 |
+
// Also see doc/precog_upg.eps
|
| 55 |
+
output busy,
|
| 56 |
+
output keep,
|
| 57 |
+
output [3:0] debug,
|
| 58 |
+
//
|
| 59 |
+
// Simple flow of data to the next processing stage (pbuf_writer).
|
| 60 |
+
// somewhat conforms to AXI-stream-lite, if I adjust the names?
|
| 61 |
+
output [7:0] odata,
|
| 62 |
+
output odata_s,
|
| 63 |
+
output odata_f,
|
| 64 |
+
output status_valid,
|
| 65 |
+
output [7:0] status_vec,
|
| 66 |
+
output [10:0] pack_len
|
| 67 |
+
);
|
| 68 |
+
// Configuration
|
| 69 |
+
parameter handle_arp = 1;
|
| 70 |
+
parameter handle_icmp = 1;
|
| 71 |
+
|
| 72 |
+
// We need enable_rx in our own clk domain
|
| 73 |
+
wire enable_rx_r;
|
| 74 |
+
reg_tech_cdc enable_rx_cdc(.I(enable_rx), .C(clk), .O(enable_rx_r));
|
| 75 |
+
|
| 76 |
+
// Ethernet frame state machine, primarily based on eth_strobe from PHY
|
| 77 |
+
wire [7:0] eth_octet = eth_in;
|
| 78 |
+
wire eth_strobe = eth_in_s;
|
| 79 |
+
// exactly four states, one-hot encoded
|
| 80 |
+
reg h_idle=1, h_preamble=0, h_data=0, h_drop=0;
|
| 81 |
+
// The exact start of frame (transition from h_preamble to h_data)
|
| 82 |
+
// is controlled by a traditional Ethernet synchronization preamble and SFD.
|
| 83 |
+
// That old-school bit-pattern of 10101010 10101010 10101011
|
| 84 |
+
// looks like 55 55 d5 when read over the 8-bit GMII port. See
|
| 85 |
+
// https://en.wikipedia.org/wiki/Ethernet_frame#Preamble_and_start_frame_delimiter
|
| 86 |
+
wire drop_packet;
|
| 87 |
+
reg [3:0] ifg_count=0; // Inter-frame gap counter
|
| 88 |
+
wire ifg_inc = ~(&ifg_count[3:2]); // saturate at 12
|
| 89 |
+
wire ifg_ok = ifg_count >= 10; // slightly relaxed from spec of 12,
|
| 90 |
+
// this configuration guarantees 11 non-data cycles between frames
|
| 91 |
+
always @(posedge clk) begin
|
| 92 |
+
if (h_idle | h_preamble) ifg_count <= ifg_count + ifg_inc;
|
| 93 |
+
else ifg_count <= 0;
|
| 94 |
+
if (h_idle & eth_strobe) begin
|
| 95 |
+
h_idle <= 0;
|
| 96 |
+
if (eth_octet==8'h55 && enable_rx_r) h_preamble <= 1;
|
| 97 |
+
else h_drop <= 1;
|
| 98 |
+
end
|
| 99 |
+
if (h_preamble) begin
|
| 100 |
+
if (eth_strobe & (eth_octet==8'hd5)) begin
|
| 101 |
+
h_preamble <= 0;
|
| 102 |
+
if (ifg_ok) h_data <= 1;
|
| 103 |
+
else h_drop <= 1; // IFG too small.
|
| 104 |
+
end else if (eth_strobe & (eth_octet!=8'h55)) begin
|
| 105 |
+
h_preamble <= 0; h_drop <= 1;
|
| 106 |
+
end else if (~eth_strobe) begin
|
| 107 |
+
h_preamble <= 0; h_idle <= 1;
|
| 108 |
+
end
|
| 109 |
+
end
|
| 110 |
+
if (h_data) begin
|
| 111 |
+
if (~eth_strobe) begin
|
| 112 |
+
h_data <= 0; h_idle <= 1;
|
| 113 |
+
end else if (drop_packet) begin // poorly tested
|
| 114 |
+
h_data <= 0; h_drop <= 1;
|
| 115 |
+
end
|
| 116 |
+
end
|
| 117 |
+
if (h_drop & ~eth_strobe) begin
|
| 118 |
+
h_drop <= 0; h_idle <= 1;
|
| 119 |
+
end
|
| 120 |
+
end
|
| 121 |
+
|
| 122 |
+
// Debug helper
|
| 123 |
+
reg [1:0] debug1_r=0;
|
| 124 |
+
always @(posedge clk) begin
|
| 125 |
+
if (h_idle) debug1_r <= 0;
|
| 126 |
+
if (h_preamble) debug1_r <= 1;
|
| 127 |
+
if (h_data) debug1_r <= 3;
|
| 128 |
+
if (h_drop) debug1_r <= 2;
|
| 129 |
+
end
|
| 130 |
+
|
| 131 |
+
// Synchronization and pipelining step
|
| 132 |
+
// Squelch data that isn't being considered
|
| 133 |
+
reg h_data_d1=0, h_data_d2=0, data_first=0;
|
| 134 |
+
reg [7:0] data_d1=0, data_d2=0;
|
| 135 |
+
always @(posedge clk) begin
|
| 136 |
+
h_data_d1 <= h_data;
|
| 137 |
+
h_data_d2 <= h_data & h_data_d1; // XXX horrible hack
|
| 138 |
+
// Why does h_data last one octet past last Ethernet octet in data?
|
| 139 |
+
data_first <= h_data & ~h_data_d1;
|
| 140 |
+
data_d1 <= eth_strobe ? eth_octet : 8'b0;
|
| 141 |
+
data_d2 <= data_d1;
|
| 142 |
+
end
|
| 143 |
+
|
| 144 |
+
// Unified handling of MAC/IP addresses via external config memory
|
| 145 |
+
//
|
| 146 |
+
// Ethernet
|
| 147 |
+
// Dest MAC: octets 0-5 match me (might be FF for broadcast)
|
| 148 |
+
// Source MAC: octets 6-11
|
| 149 |
+
//
|
| 150 |
+
// ARP (RFC 826)
|
| 151 |
+
// Sender MAC: octets 22-27
|
| 152 |
+
// Sender IP: octets 28-31
|
| 153 |
+
// Placeholder: octets 32-37
|
| 154 |
+
// Dest IP: octets 38-41 match me
|
| 155 |
+
//
|
| 156 |
+
// IP (RFC 791)
|
| 157 |
+
// Source IP: octets 26-29
|
| 158 |
+
// Dest IP: octets 30-33 match me
|
| 159 |
+
//
|
| 160 |
+
// ICMP (RFC 792)
|
| 161 |
+
// UDP (RFC 768)
|
| 162 |
+
//
|
| 163 |
+
reg [10:0] pack_cnt=0;
|
| 164 |
+
always @(posedge clk) begin
|
| 165 |
+
pack_cnt <= h_data ? pack_cnt+1 : 0;
|
| 166 |
+
end
|
| 167 |
+
assign drop_packet = pack_cnt >= 1536;
|
| 168 |
+
assign ip_a = pack_cnt > 36 || pack_cnt < 16 ? pack_cnt[3:0] : pack_cnt[3:0]+8;
|
| 169 |
+
wire ip_m = ip_d == data_d1;
|
| 170 |
+
// This pack_cnt decoding is synthesizable as is; we can make it more gate-
|
| 171 |
+
// efficient later, using synthesis measurements and good regression tests.
|
| 172 |
+
reg want_c_eth=0, want_c_arp=0, want_c_ip=0;
|
| 173 |
+
always @(posedge clk) begin
|
| 174 |
+
want_c_eth <= pack_cnt < 6;
|
| 175 |
+
want_c_arp <= pack_cnt >= 38 && pack_cnt < 42;
|
| 176 |
+
want_c_ip <= pack_cnt >= 30 && pack_cnt < 34;
|
| 177 |
+
end
|
| 178 |
+
// Accumulate state
|
| 179 |
+
wire pz = pack_cnt == 0;
|
| 180 |
+
reg pass_ethmac=0; always @(posedge clk) begin if (want_c_eth & ~ip_m) pass_ethmac <= 0; if (pz) pass_ethmac <= 1; end
|
| 181 |
+
reg pass_arpip=0; always @(posedge clk) begin if (want_c_arp & ~ip_m) pass_arpip <= 0; if (pz) pass_arpip <= 1; end
|
| 182 |
+
reg pass_ipdst=0; always @(posedge clk) begin if (want_c_ip & ~ip_m) pass_ipdst <= 0; if (pz) pass_ipdst <= 1; end
|
| 183 |
+
|
| 184 |
+
// Specific protocols; IP is a component of both ICMP and UDP
|
| 185 |
+
wire [15:0] ip_length, udp_length;
|
| 186 |
+
|
| 187 |
+
// ARP handling is optional, chosen by the handle_arp parameter.
|
| 188 |
+
wire pass_arp0;
|
| 189 |
+
generate if (handle_arp) begin : find_arp
|
| 190 |
+
arp_patt arp_p (.clk(clk), .cnt(pack_cnt), .data(data_d1), .pass(pass_arp0));
|
| 191 |
+
end else begin : no_find_arp
|
| 192 |
+
assign pass_arp0 = 0;
|
| 193 |
+
end endgenerate
|
| 194 |
+
|
| 195 |
+
// ICMP handling is optional, chosen by the handle_icmp parameter.
|
| 196 |
+
wire pass_icmp0;
|
| 197 |
+
generate if (handle_icmp) begin : find_icmp
|
| 198 |
+
icmp_patt icmp_p(.clk(clk), .cnt(pack_cnt), .data(data_d1), .pass(pass_icmp0));
|
| 199 |
+
end else begin : no_find_icmp
|
| 200 |
+
assign pass_icmp0 = 0;
|
| 201 |
+
end endgenerate
|
| 202 |
+
|
| 203 |
+
// IP, UDP, and checksum handling are given, but see note below about UDP checksums.
|
| 204 |
+
wire pass_ip0; ip_patt ip_p (.clk(clk), .cnt(pack_cnt), .data(data_d1), .pass(pass_ip0), .length(ip_length));
|
| 205 |
+
wire pass_udp0; udp_patt udp_p (.clk(clk), .cnt(pack_cnt), .data(data_d1), .pass(pass_udp0), .length(udp_length));
|
| 206 |
+
wire pass_sum; cksum_chk chk_p (.clk(clk), .cnt(pack_cnt), .data(data_d1), .pass(pass_sum), .length(ip_length));
|
| 207 |
+
|
| 208 |
+
// CRC32
|
| 209 |
+
wire crc_zero;
|
| 210 |
+
crc8e_guts crc8e(.clk(clk), .gate(h_data_d1), .first(data_first),
|
| 211 |
+
.d_in(data_d1), .zero(crc_zero));
|
| 212 |
+
wire final_octet = h_data_d1 & ~h_data;
|
| 213 |
+
|
| 214 |
+
// UDP port number
|
| 215 |
+
reg udp_port_stb=0;
|
| 216 |
+
always @(posedge clk) udp_port_stb <= pack_cnt == 36;
|
| 217 |
+
wire [2:0] port_p0; wire port_h, port_v;
|
| 218 |
+
udp_port_cam #(.naw(3)) cam(.clk(clk),
|
| 219 |
+
.port_s(udp_port_stb), .data(data_d1),
|
| 220 |
+
.pno_a(pno_a), .pno_d(pno_d),
|
| 221 |
+
.port_p(port_p0), .port_h(port_h), .port_v(port_v)
|
| 222 |
+
);
|
| 223 |
+
|
| 224 |
+
// Packet length (doesn't count GMII preamble)
|
| 225 |
+
reg [10:0] pack_len_r=0;
|
| 226 |
+
always @(posedge clk) if (h_data) pack_len_r <= pack_cnt;
|
| 227 |
+
|
| 228 |
+
// Weird place for this
|
| 229 |
+
reg ip_len_check=0, udp_len_check=0;
|
| 230 |
+
always @(posedge clk) if (h_data) begin
|
| 231 |
+
ip_len_check <= pack_cnt >= ip_length + 18; // 18 = 14 Ethernet header + 4 CRC
|
| 232 |
+
udp_len_check <= ip_length >= udp_length + 20; // 20 = IP header length
|
| 233 |
+
end
|
| 234 |
+
|
| 235 |
+
// One more oddball
|
| 236 |
+
reg unicast_src_mac=0;
|
| 237 |
+
always @(posedge clk) begin
|
| 238 |
+
if (pack_cnt==1) unicast_src_mac <= 1; // optimistic, needed to make busy flag work
|
| 239 |
+
if (pack_cnt==7) unicast_src_mac <= ~data_d1[0];
|
| 240 |
+
end
|
| 241 |
+
|
| 242 |
+
// Summary bits (mostly) don't leak irrelevant state
|
| 243 |
+
wire pass_arp = unicast_src_mac & crc_zero & pass_arp0 & pass_arpip;
|
| 244 |
+
wire pass_ip = unicast_src_mac & crc_zero & pass_ethmac & pass_ip0 & pass_ipdst & ip_len_check;
|
| 245 |
+
wire pass_icmp = pass_ip & pass_icmp0 & pass_sum;
|
| 246 |
+
wire pass_udp = pass_ip & pass_udp0 & udp_len_check & port_h;
|
| 247 |
+
wire [1:0] category = pass_udp ? 3 : pass_icmp ? 2 : pass_arp ? 1 : 0;
|
| 248 |
+
wire [2:0] port_p = pass_udp ? port_p0 : 3'd0;
|
| 249 |
+
|
| 250 |
+
// Summary output
|
| 251 |
+
assign status_vec = {port_p, pass_ip, pass_ethmac, crc_zero, category};
|
| 252 |
+
assign status_valid = final_octet;
|
| 253 |
+
assign pack_len = pack_len_r;
|
| 254 |
+
|
| 255 |
+
// Other summary output
|
| 256 |
+
wire busy_with_arp = unicast_src_mac & pass_arp0;
|
| 257 |
+
wire busy_with_udp = unicast_src_mac & pass_ethmac & pass_ip0 & pass_udp0;
|
| 258 |
+
wire busy_with_icmp = unicast_src_mac & pass_ethmac & pass_ip0 & pass_icmp0;
|
| 259 |
+
reg busy_r=0, keep_r=0;
|
| 260 |
+
always @(posedge clk) begin
|
| 261 |
+
busy_r <= odata_s & (busy_with_arp | busy_with_udp | busy_with_icmp);
|
| 262 |
+
keep_r <= odata_s & (category != 0);
|
| 263 |
+
end
|
| 264 |
+
assign busy = busy_r;
|
| 265 |
+
assign keep = keep_r;
|
| 266 |
+
|
| 267 |
+
// Debug helper
|
| 268 |
+
reg [1:0] debug2_r=0;
|
| 269 |
+
always @(posedge clk) begin
|
| 270 |
+
if (status_valid) debug2_r <= category;
|
| 271 |
+
end
|
| 272 |
+
assign debug = {debug2_r, debug1_r};
|
| 273 |
+
|
| 274 |
+
// Output ports
|
| 275 |
+
assign odata = data_d2;
|
| 276 |
+
assign odata_s = h_data_d2;
|
| 277 |
+
assign odata_f = final_octet;
|
| 278 |
+
|
| 279 |
+
endmodule
|
| 280 |
+
|
| 281 |
+
// New modules to get new name spaces
|
| 282 |
+
|
| 283 |
+
// =====
|
| 284 |
+
// UDP/ICMP Checksum checker
|
| 285 |
+
// Calculation structure for UDP and ICMP is about the same, so it
|
| 286 |
+
// superficially looks like we just need a little stream selection logic
|
| 287 |
+
// based on the protocol, and then a single one's-complement accumulator
|
| 288 |
+
// could handle both cases.
|
| 289 |
+
// This rosy scenario is stymied by UDP's pathological inclusion of
|
| 290 |
+
// _two_ copies of the UDP length. At the moment, therefore, this
|
| 291 |
+
// module doesn't handle UDP.
|
| 292 |
+
module cksum_chk(
|
| 293 |
+
input clk,
|
| 294 |
+
input [10:0] cnt,
|
| 295 |
+
input [7:0] data,
|
| 296 |
+
input [15:0] length, // IP length
|
| 297 |
+
output pass
|
| 298 |
+
);
|
| 299 |
+
|
| 300 |
+
wire chksum_zero = cnt == 22; // or earlier
|
| 301 |
+
wire icmp_gate = cnt >= 35;
|
| 302 |
+
// wire udp_gate = cnt >= 23;
|
| 303 |
+
wire chksum_gate = icmp_gate;
|
| 304 |
+
|
| 305 |
+
// Make sure length is known before using it
|
| 306 |
+
wire end_of_ip = cnt>32 && cnt == (length+14);
|
| 307 |
+
|
| 308 |
+
// Standard one's-complement checksum
|
| 309 |
+
wire ones;
|
| 310 |
+
ones_chksum ck(.clk(clk), .clear(chksum_zero), .gate(chksum_gate),
|
| 311 |
+
.din(data), .all_ones(ones));
|
| 312 |
+
|
| 313 |
+
// Final state, should find FF FF at end of IP packet
|
| 314 |
+
reg eof=0, state=0;
|
| 315 |
+
always @(posedge clk) begin
|
| 316 |
+
if (chksum_zero) state <= 0;
|
| 317 |
+
if (end_of_ip) state <= ones;
|
| 318 |
+
eof <= end_of_ip;
|
| 319 |
+
if (eof) state <= state & ones;
|
| 320 |
+
end
|
| 321 |
+
assign pass = state;
|
| 322 |
+
|
| 323 |
+
endmodule // UDP/ICMP Checksum checker
|
| 324 |
+
|
| 325 |
+
// =====
|
| 326 |
+
// ARP pattern checker
|
| 327 |
+
module arp_patt(
|
| 328 |
+
input clk,
|
| 329 |
+
input [10:0] cnt,
|
| 330 |
+
input [7:0] data,
|
| 331 |
+
output pass
|
| 332 |
+
);
|
| 333 |
+
|
| 334 |
+
reg [7:0] template=0;
|
| 335 |
+
always @(posedge clk) case(cnt[3:0])
|
| 336 |
+
// template starts at 12th byte of Ethernet packet,
|
| 337 |
+
// after the two MAC addresses.
|
| 338 |
+
4'd12: template <= 8'h08;
|
| 339 |
+
4'd13: template <= 8'h06;
|
| 340 |
+
4'd14: template <= 8'h00; // ARP Ethernet hardware, octet 1
|
| 341 |
+
4'd15: template <= 8'h01; // ARP Ethernet hardware, octet 2
|
| 342 |
+
4'd00: template <= 8'h08; // ARP Protocol IP
|
| 343 |
+
4'd01: template <= 8'h00; // ARP Protocol IP
|
| 344 |
+
4'd02: template <= 8'h06; // ARP protocol address length
|
| 345 |
+
4'd03: template <= 8'h04; // ARP protocol address length
|
| 346 |
+
4'd04: template <= 8'h00; // ARP protocol operation
|
| 347 |
+
4'd05: template <= 8'h01; // ARP protocol operation (request)
|
| 348 |
+
default: template <= 8'h00;
|
| 349 |
+
endcase
|
| 350 |
+
|
| 351 |
+
reg want=0, pass_r=0;
|
| 352 |
+
wire match = data == template;
|
| 353 |
+
always @(posedge clk) begin
|
| 354 |
+
want <= cnt >= 12 && cnt < 22;
|
| 355 |
+
if (cnt == 0) pass_r <= 1;
|
| 356 |
+
if (want & ~match) pass_r <= 0;
|
| 357 |
+
end
|
| 358 |
+
assign pass = pass_r;
|
| 359 |
+
|
| 360 |
+
endmodule // ARP pattern checker
|
| 361 |
+
|
| 362 |
+
// =====
|
| 363 |
+
// IP pattern checker
|
| 364 |
+
module ip_patt(
|
| 365 |
+
input clk,
|
| 366 |
+
input [10:0] cnt,
|
| 367 |
+
input [7:0] data,
|
| 368 |
+
output pass,
|
| 369 |
+
output [15:0] length
|
| 370 |
+
);
|
| 371 |
+
|
| 372 |
+
reg [7:0] template=0;
|
| 373 |
+
always @(posedge clk) case(cnt[4:0])
|
| 374 |
+
// template starts at 12th byte of Ethernet packet,
|
| 375 |
+
// after the two MAC addresses.
|
| 376 |
+
5'd12: template <= 8'h08; // Bytes 12 and 13 are Ethertype IPv4
|
| 377 |
+
5'd13: template <= 8'h00; // https://en.wikipedia.org/wiki/Ethertype
|
| 378 |
+
|
| 379 |
+
// Start of IPv4 header [https://en.wikipedia.org/wiki/IPv4#Header]
|
| 380 |
+
5'd14: template <= 8'h45; // Vers (4 for ipv4) / IHL (> 5 is a weird case)
|
| 381 |
+
// 15 ignore TOS (later changed to DSCP and ECN)
|
| 382 |
+
// 16 ignore length msb
|
| 383 |
+
// 17 ignore length lsb
|
| 384 |
+
// 18 ignore identification msb
|
| 385 |
+
// 19 ignore identification lsb
|
| 386 |
+
5'd20: template <= 8'h00; // Flags/Fragment
|
| 387 |
+
5'd21: template <= 8'h00;
|
| 388 |
+
// 22 ignore TTL (but see below)
|
| 389 |
+
// 23 ignore Protocol
|
| 390 |
+
// 24-33 header checksum, source address, destination address
|
| 391 |
+
default: template <= 8'h00;
|
| 392 |
+
endcase
|
| 393 |
+
|
| 394 |
+
// Packet has expired when TTL hits zero
|
| 395 |
+
reg ttl_flag=0;
|
| 396 |
+
wire zero_ttl = ttl_flag & ~(|data);
|
| 397 |
+
|
| 398 |
+
reg want=0, mask_df_bit=0, pass_r=0;
|
| 399 |
+
wire [7:0] df_mask = {1'b1, ~mask_df_bit, 6'h3f};
|
| 400 |
+
wire match = (data&df_mask) == template;
|
| 401 |
+
always @(posedge clk) begin
|
| 402 |
+
want <= cnt >= 12 && cnt < 15 || cnt >= 20 && cnt < 22;
|
| 403 |
+
mask_df_bit <= cnt == 20;
|
| 404 |
+
ttl_flag <= cnt == 22;
|
| 405 |
+
if (cnt == 0) pass_r <= 1;
|
| 406 |
+
if (want & ~match) pass_r <= 0;
|
| 407 |
+
if (zero_ttl) pass_r <= 0;
|
| 408 |
+
end
|
| 409 |
+
|
| 410 |
+
// IP packet total length
|
| 411 |
+
// Quoting RFC 791, Total Length is the length of the datagram,
|
| 412 |
+
// measured in octets, including internet header and data.
|
| 413 |
+
reg [7:0] data_d=0;
|
| 414 |
+
reg [15:0] length_r=0;
|
| 415 |
+
always @(posedge clk) begin
|
| 416 |
+
data_d <= data;
|
| 417 |
+
if (cnt==18) length_r <= {data_d, data};
|
| 418 |
+
end
|
| 419 |
+
assign length = length_r;
|
| 420 |
+
|
| 421 |
+
// IP header checksum
|
| 422 |
+
reg out_chksum_gate=0, out_chksum_zero=0;
|
| 423 |
+
always @(posedge clk) begin
|
| 424 |
+
out_chksum_gate <= cnt >= 14 && cnt < 34;
|
| 425 |
+
out_chksum_zero <= cnt == 0;
|
| 426 |
+
end
|
| 427 |
+
wire chksum_all_ones;
|
| 428 |
+
ones_chksum ck(.clk(clk), .clear(out_chksum_zero), .gate(out_chksum_gate),
|
| 429 |
+
.din(data), .all_ones(chksum_all_ones));
|
| 430 |
+
reg chksum_all_ones_d=0;
|
| 431 |
+
reg chksum_fail=0;
|
| 432 |
+
always @(posedge clk) begin
|
| 433 |
+
chksum_all_ones_d <= chksum_all_ones;
|
| 434 |
+
if (cnt==0) chksum_fail <= 0;
|
| 435 |
+
if (cnt==35) chksum_fail <= ~chksum_all_ones | ~chksum_all_ones_d;
|
| 436 |
+
end
|
| 437 |
+
assign pass = pass_r & ~chksum_fail;
|
| 438 |
+
|
| 439 |
+
endmodule // IP header
|
| 440 |
+
|
| 441 |
+
// =====
|
| 442 |
+
// ICMP pattern checker
|
| 443 |
+
// For ICMP checksum see module cksum_chk
|
| 444 |
+
module icmp_patt(
|
| 445 |
+
input clk,
|
| 446 |
+
input [10:0] cnt,
|
| 447 |
+
input [7:0] data,
|
| 448 |
+
output pass
|
| 449 |
+
);
|
| 450 |
+
|
| 451 |
+
reg [7:0] template=0;
|
| 452 |
+
always @(posedge clk) case(cnt[2:0])
|
| 453 |
+
// Ethernet/IP header is not in our scope
|
| 454 |
+
// template starts at 23rd byte of Ethernet packet,
|
| 455 |
+
// after the two MAC addresses.
|
| 456 |
+
3'd7: template <= 8'h01; // cnt==23, Proto (ICMP)
|
| 457 |
+
3'd2: template <= 8'h08; // cnt==34, ICMP echo request
|
| 458 |
+
3'd3: template <= 8'h00; // cnt==35, ICMP code
|
| 459 |
+
default: template <= 8'h00;
|
| 460 |
+
endcase
|
| 461 |
+
|
| 462 |
+
reg want=0, pass_r=0;
|
| 463 |
+
wire match = data == template;
|
| 464 |
+
always @(posedge clk) begin
|
| 465 |
+
want <= cnt == 23 || cnt==34 || cnt==35;
|
| 466 |
+
if (cnt == 0) pass_r <= 1;
|
| 467 |
+
if (want & ~match) pass_r <= 0;
|
| 468 |
+
end
|
| 469 |
+
assign pass = pass_r;
|
| 470 |
+
|
| 471 |
+
endmodule // ICMP pattern checker
|
| 472 |
+
|
| 473 |
+
// =====
|
| 474 |
+
// UDP pattern checker
|
| 475 |
+
module udp_patt(
|
| 476 |
+
input clk,
|
| 477 |
+
input [10:0] cnt,
|
| 478 |
+
input [7:0] data,
|
| 479 |
+
output pass,
|
| 480 |
+
output [15:0] length
|
| 481 |
+
);
|
| 482 |
+
|
| 483 |
+
// Degenerate form of template ROM
|
| 484 |
+
// Moving this template and comparison to ip_patt would save 2 LUTs.
|
| 485 |
+
wire [7:0] template = 8'h11; // cnt==23, Proto (UDP)
|
| 486 |
+
|
| 487 |
+
// Reject packets from source port number < 1024,
|
| 488 |
+
// as they come from "trusted" sources.
|
| 489 |
+
// This is part of the strategy to resist echo loops.
|
| 490 |
+
wire reject_low = cnt==35 & ~|data[7:2];
|
| 491 |
+
|
| 492 |
+
// Reject packets to destination port number 0
|
| 493 |
+
reg pzero_d=0, pzero_d1=0, pzero_t=0;
|
| 494 |
+
always @(posedge clk) begin
|
| 495 |
+
pzero_d <= data == 8'h00;
|
| 496 |
+
pzero_d1 <= pzero_d;
|
| 497 |
+
pzero_t <= cnt == 36;
|
| 498 |
+
end
|
| 499 |
+
wire discard_port0 = pzero_t & pzero_d & pzero_d1;
|
| 500 |
+
|
| 501 |
+
reg want=0, pass_r=0;
|
| 502 |
+
wire match = data == template;
|
| 503 |
+
always @(posedge clk) begin
|
| 504 |
+
want <= cnt == 23;
|
| 505 |
+
if (cnt == 0) pass_r <= 1;
|
| 506 |
+
if (want & ~match) pass_r <= 0;
|
| 507 |
+
if (reject_low) pass_r <= 0;
|
| 508 |
+
if (discard_port0) pass_r <= 0;
|
| 509 |
+
end
|
| 510 |
+
assign pass = pass_r;
|
| 511 |
+
|
| 512 |
+
// UDP packet length
|
| 513 |
+
// Length is the length in octets of this user datagram including [UDP]
|
| 514 |
+
// header and the data.
|
| 515 |
+
reg [7:0] data_d=0;
|
| 516 |
+
reg [15:0] length_r=0;
|
| 517 |
+
always @(posedge clk) begin
|
| 518 |
+
data_d <= data;
|
| 519 |
+
if (cnt==40) length_r <= {data_d, data};
|
| 520 |
+
end
|
| 521 |
+
assign length = length_r;
|
| 522 |
+
|
| 523 |
+
// XXX We don't yet compute the UDP checksum.
|
| 524 |
+
// That may not be a practical problem.
|
| 525 |
+
|
| 526 |
+
endmodule // UDP pattern checker
|
BerkeleyLab_Bedrock/badger/speed_test.v
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Speed test client
|
| 2 |
+
// A lot like a UDP echo, but more satisfying because it actually
|
| 3 |
+
// changes the data that flows through it.
|
| 4 |
+
// Compatible with ethernet-core/core/client_thru.v
|
| 5 |
+
// and ethernet-core/runtime/udprtx.c
|
| 6 |
+
module speed_test(
|
| 7 |
+
input clk,
|
| 8 |
+
input nomangle, // software settable
|
| 9 |
+
// client interface with RTEFI, see doc/clients.eps
|
| 10 |
+
input [10:0] len_c,
|
| 11 |
+
input [7:0] idata,
|
| 12 |
+
input raw_l,
|
| 13 |
+
input raw_s,
|
| 14 |
+
output [7:0] odata
|
| 15 |
+
);
|
| 16 |
+
|
| 17 |
+
parameter n_lat=2; // minimum value is 1
|
| 18 |
+
|
| 19 |
+
// len_c counts down to 9, but we need something that counts up from 0
|
| 20 |
+
reg [7:0] count=0;
|
| 21 |
+
reg [7:0] processed=0;
|
| 22 |
+
always @(posedge clk) begin
|
| 23 |
+
count <= raw_s ? count+1 : 0;
|
| 24 |
+
processed <= idata ^ (count & {8{~nomangle}});
|
| 25 |
+
end
|
| 26 |
+
|
| 27 |
+
// 13 bits input, 8 bits output, choose to pipeline output
|
| 28 |
+
reg_delay #(.len(n_lat-1), .dw(8)) align(.clk(clk), .gate(1'b1), .reset(1'b0),
|
| 29 |
+
.din(processed), .dout(odata));
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/spi_flash.v
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Mechanism to reprogram boot flash
|
| 2 |
+
module spi_flash(
|
| 3 |
+
input clk,
|
| 4 |
+
// client interface with RTEFI, see doc/clients.eps
|
| 5 |
+
input [10:0] len_c,
|
| 6 |
+
input [7:0] idata,
|
| 7 |
+
input raw_l,
|
| 8 |
+
input raw_s,
|
| 9 |
+
output [7:0] odata,
|
| 10 |
+
// 4-wire to e.g., Winbond W25X16
|
| 11 |
+
output spi_clk,
|
| 12 |
+
output spi_cs,
|
| 13 |
+
output spi_mosi,
|
| 14 |
+
input spi_miso,
|
| 15 |
+
output busy // only intended for simulation
|
| 16 |
+
);
|
| 17 |
+
|
| 18 |
+
parameter n_lat = 8; // latency of client pipeline
|
| 19 |
+
|
| 20 |
+
// Try really hard to be non-fancy here, just the obvious way of
|
| 21 |
+
// gatewaying the previously functioning spi_flash_engine into
|
| 22 |
+
// the RTEFI scheme.
|
| 23 |
+
|
| 24 |
+
// Longer term it would be nice if this could be re-written to
|
| 25 |
+
// allow more resource sharing, say between Rx and Tx buffers,
|
| 26 |
+
// and code sharing with other buffered clients, like the SPI
|
| 27 |
+
// slave gateway to a microcontroller, as was done in PSPEPS.
|
| 28 |
+
|
| 29 |
+
// This module cries out to be a customer of an authentication
|
| 30 |
+
// mechanism, whenever that becomes available.
|
| 31 |
+
|
| 32 |
+
parameter aw=9; // nominal/minimal 512 x 8
|
| 33 |
+
reg [7:0] rx_mem[0:(1<<aw)-1];
|
| 34 |
+
reg [7:0] tx_mem[0:(1<<aw)-1];
|
| 35 |
+
|
| 36 |
+
reg pack_read_ready=0;
|
| 37 |
+
reg [8:0] rx_packet_len;
|
| 38 |
+
wire pack_read_strobe;
|
| 39 |
+
reg [7:0] pack_data_rx=0;
|
| 40 |
+
|
| 41 |
+
wire pack_read_done;
|
| 42 |
+
wire pack_write;
|
| 43 |
+
wire pack_write_ack=pack_read_ready;
|
| 44 |
+
wire pack_write_strobe;
|
| 45 |
+
wire [7:0] pack_data_tx;
|
| 46 |
+
|
| 47 |
+
spi_flash_engine engine(
|
| 48 |
+
.clk(clk),
|
| 49 |
+
.spi_clk(spi_clk),
|
| 50 |
+
.spi_cs(spi_cs),
|
| 51 |
+
.spi_mosi(spi_mosi),
|
| 52 |
+
.spi_miso(spi_miso),
|
| 53 |
+
//
|
| 54 |
+
.pack_read_ready(pack_read_ready),
|
| 55 |
+
.input_packet_len(rx_packet_len),
|
| 56 |
+
.pack_read_strobe(pack_read_strobe),
|
| 57 |
+
.pack_data_in(pack_data_rx),
|
| 58 |
+
.pack_read_done(pack_read_done),
|
| 59 |
+
//
|
| 60 |
+
.pack_write(pack_write),
|
| 61 |
+
.pack_write_ack(pack_write_ack),
|
| 62 |
+
.pack_write_strobe(pack_write_strobe),
|
| 63 |
+
.pack_data_out(pack_data_tx)
|
| 64 |
+
);
|
| 65 |
+
|
| 66 |
+
// Adapt the RTEFI control lines into what we need;
|
| 67 |
+
// shared between Rx writer and Tx reader.
|
| 68 |
+
reg [1:0] raw_sr=0;
|
| 69 |
+
reg [aw-1:0] eth_point=0;
|
| 70 |
+
always @(posedge clk) begin
|
| 71 |
+
raw_sr <= {raw_sr[0:0], raw_s};
|
| 72 |
+
eth_point <= raw_sr[1] ? eth_point+1 : 0;
|
| 73 |
+
end
|
| 74 |
+
|
| 75 |
+
// Logic for writing Rx memory
|
| 76 |
+
// Note the decoding of the first byte as a packet-global op-code:
|
| 77 |
+
// 0x52 write buffer
|
| 78 |
+
// The write command will fail if the buffer is not empty, and that
|
| 79 |
+
// failure gets reported in the status message, below, right?
|
| 80 |
+
reg rx_for_us=0, write_pack_flag=0;
|
| 81 |
+
wire rx_mem_write = raw_s & raw_sr[1] & write_pack_flag;
|
| 82 |
+
wire pre_write_pack_flag = rx_for_us & idata[0];
|
| 83 |
+
always @(posedge clk) begin
|
| 84 |
+
if (raw_s & ~raw_sr[0]) rx_for_us <= (idata == 8'h52) && ~pack_read_ready;
|
| 85 |
+
if (raw_sr[0] & ~raw_sr[1]) write_pack_flag <= pre_write_pack_flag;
|
| 86 |
+
if (rx_mem_write) rx_mem[eth_point] <= idata;
|
| 87 |
+
if (raw_sr[0] & ~raw_s & write_pack_flag) pack_read_ready <= 1;
|
| 88 |
+
if (raw_sr[0] & ~raw_s & write_pack_flag) rx_packet_len <= eth_point;
|
| 89 |
+
if (pack_read_done) pack_read_ready <= 0;
|
| 90 |
+
end
|
| 91 |
+
|
| 92 |
+
// Logic for reading Rx memory
|
| 93 |
+
reg [aw-1:0] rx_rpoint=0;
|
| 94 |
+
always @(posedge clk) begin
|
| 95 |
+
if (pack_read_done) rx_rpoint <= 0;
|
| 96 |
+
if (pack_read_strobe & pack_read_ready) rx_rpoint <= rx_rpoint+1;
|
| 97 |
+
pack_data_rx <= rx_mem[rx_rpoint];
|
| 98 |
+
end
|
| 99 |
+
|
| 100 |
+
// Logic for writing Tx memory
|
| 101 |
+
reg [aw-1:0] tx_wpoint=0;
|
| 102 |
+
always @(posedge clk) begin
|
| 103 |
+
if (pack_write_strobe) begin
|
| 104 |
+
tx_mem[tx_wpoint] <= pack_data_tx;
|
| 105 |
+
tx_wpoint <= tx_wpoint+1;
|
| 106 |
+
end
|
| 107 |
+
if (~pack_write) tx_wpoint <= 0;
|
| 108 |
+
end
|
| 109 |
+
|
| 110 |
+
// Logic for reading Tx memory
|
| 111 |
+
// len_c counts down to 9, but we need something that counts up from 0
|
| 112 |
+
wire [7:0] tx_status = {pre_write_pack_flag, ~pack_read_ready};
|
| 113 |
+
reg [7:0] tx_rdata=0, odata1=0;
|
| 114 |
+
always @(posedge clk) begin
|
| 115 |
+
tx_rdata <= tx_mem[eth_point];
|
| 116 |
+
odata1 <= raw_sr[1] ? tx_rdata : raw_sr[0] ? tx_status : 8'h51;
|
| 117 |
+
end
|
| 118 |
+
|
| 119 |
+
// Internal-only for viewing in simulation
|
| 120 |
+
reg [7:0] status_report;
|
| 121 |
+
wire status_capture_tick = ~raw_sr[1] & raw_sr[0];
|
| 122 |
+
always @(posedge clk) if (status_capture_tick) status_report <= tx_status;
|
| 123 |
+
|
| 124 |
+
// output packet:
|
| 125 |
+
// message type
|
| 126 |
+
// status byte
|
| 127 |
+
// buffer memory
|
| 128 |
+
// how about buffer length, i.e., tx_wpoint before it got erased?
|
| 129 |
+
|
| 130 |
+
// choose to pipeline output
|
| 131 |
+
reg_delay #(.len(n_lat-1), .dw(8)) align(.clk(clk), .gate(1'b1), .reset(1'b0),
|
| 132 |
+
.din(odata1), .dout(odata));
|
| 133 |
+
|
| 134 |
+
assign busy = pack_read_ready;
|
| 135 |
+
|
| 136 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/spi_flash_engine.v
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module spi_flash_engine(
|
| 2 |
+
input clk,
|
| 3 |
+
// 4-wire to e.g., Winbond W25X16
|
| 4 |
+
output spi_clk,
|
| 5 |
+
output spi_cs,
|
| 6 |
+
output spi_mosi,
|
| 7 |
+
input spi_miso,
|
| 8 |
+
// port to read packet memory
|
| 9 |
+
input pack_read_ready,
|
| 10 |
+
input [8:0] input_packet_len,
|
| 11 |
+
output pack_read_strobe,
|
| 12 |
+
input [7:0] pack_data_in,
|
| 13 |
+
output pack_read_done, // marks memory as empty
|
| 14 |
+
// port to write packet memory
|
| 15 |
+
output pack_write, // high for whole transaction
|
| 16 |
+
input pack_write_ack, // see below
|
| 17 |
+
output pack_write_strobe, // single-cycle for each data byte
|
| 18 |
+
output [7:0] pack_data_out
|
| 19 |
+
);
|
| 20 |
+
|
| 21 |
+
parameter xc6slx = 0; // Include gateway to an ICAP_SPARTAN6
|
| 22 |
+
parameter seven = 0; // Include gateway to an ICAPE2 on Xilinx 7-series
|
| 23 |
+
|
| 24 |
+
// packet write, and indeed the whole engine, will stall until
|
| 25 |
+
// pack_write_ack is received. The ack will often happen immediately,
|
| 26 |
+
// but can be substantially delayed if the output packet buffer is busy
|
| 27 |
+
// handling a microcontroller output packet.
|
| 28 |
+
|
| 29 |
+
// spi_clk is rated to 50 MHz, but we have no real reason to push this.
|
| 30 |
+
// Most of the clock time will be spent after the write or erase SPI
|
| 31 |
+
// transactions, waiting for the busy flag to go away.
|
| 32 |
+
// Use 32 ns high / 32 ns low, 15.6 MBit/s.
|
| 33 |
+
|
| 34 |
+
// Abstract spi_mosi is valid 4 cycles before and 4 cycles after the rising
|
| 35 |
+
// edge of spi_clk. The real W25Xxx requires the real data pin valid 2ns
|
| 36 |
+
// before and 5ns after the rising edge of the real clock pin.
|
| 37 |
+
|
| 38 |
+
// The real X25Xxx specifies its data is output 0ns to 7ns after the falling
|
| 39 |
+
// edge of its clock. This module samples spi_miso on the rising edge
|
| 40 |
+
// of spi_clk.
|
| 41 |
+
|
| 42 |
+
// Encode length byte as
|
| 43 |
+
// 256 4 2 1
|
| 44 |
+
// Allows likely lengths 1, 2, 4, 6, 260, and 261.
|
| 45 |
+
// Leaves additional control bits to possibly encode a special
|
| 46 |
+
// "read status register repeatedly until done" mode.
|
| 47 |
+
|
| 48 |
+
reg running=0;
|
| 49 |
+
reg [8:0] block_len=0;
|
| 50 |
+
reg [8:0] bytes_remaining=0;
|
| 51 |
+
reg word=0;
|
| 52 |
+
reg icap_en=0;
|
| 53 |
+
reg word2=0, word3=0, word4=0;
|
| 54 |
+
always @(posedge clk) begin
|
| 55 |
+
if (pack_write_ack & word & ~running) begin
|
| 56 |
+
running<=1;
|
| 57 |
+
bytes_remaining<=input_packet_len;
|
| 58 |
+
end else begin
|
| 59 |
+
if (~pack_read_ready | (bytes_remaining==0)) running<=0;
|
| 60 |
+
end
|
| 61 |
+
if (running & word2) begin
|
| 62 |
+
block_len <= (|block_len) ? (block_len-1) : {pack_data_in[3],5'b0,pack_data_in[2:0]};
|
| 63 |
+
if (~(|block_len)) icap_en <= pack_data_in[7];
|
| 64 |
+
bytes_remaining <= bytes_remaining-1;
|
| 65 |
+
end
|
| 66 |
+
if (running & word3 & ~(|block_len)) icap_en <= 0;
|
| 67 |
+
if (!running) icap_en <= 0;
|
| 68 |
+
end
|
| 69 |
+
|
| 70 |
+
reg [6:0] subtick=0;
|
| 71 |
+
reg [7:0] sr=0;
|
| 72 |
+
reg tick=0, tick2=0, tick3=0, tick4=0;
|
| 73 |
+
reg spi_clk_r=0, spi_clk_rr=0, spi_miso_r=0, spi_cs_pre=0, spi_cs_r=0, in_bit=0;
|
| 74 |
+
wire [7:0] sr_next = {sr[6:0], in_bit};
|
| 75 |
+
always @(posedge clk) begin
|
| 76 |
+
subtick <= subtick+1;
|
| 77 |
+
tick <= subtick[3:0]==13;
|
| 78 |
+
tick2 <= tick;
|
| 79 |
+
tick3 <= tick2;
|
| 80 |
+
tick4 <= tick3;
|
| 81 |
+
word <= subtick==125;
|
| 82 |
+
word2 <= word;
|
| 83 |
+
word3 <= word2;
|
| 84 |
+
word4 <= word3;
|
| 85 |
+
spi_clk_r <= subtick[3]&running&~icap_en&(|block_len);
|
| 86 |
+
spi_clk_rr <= spi_clk_r;
|
| 87 |
+
spi_miso_r <= spi_miso; // IOB
|
| 88 |
+
if (subtick[3:0]==11) in_bit <= spi_cs_r ? spi_miso_r : 1'b0;
|
| 89 |
+
spi_cs_pre <= running&~icap_en&(|block_len)&(|bytes_remaining);
|
| 90 |
+
spi_cs_r <= spi_cs_pre;
|
| 91 |
+
if (tick4 & running) sr <= (word4&(|block_len)) ? pack_data_in : sr_next;
|
| 92 |
+
end
|
| 93 |
+
|
| 94 |
+
assign spi_clk=spi_clk_rr;
|
| 95 |
+
assign spi_cs=~spi_cs_r;
|
| 96 |
+
assign spi_mosi=sr[7]&spi_cs_r;
|
| 97 |
+
|
| 98 |
+
// Optional support for ICAP_SPARTAN6
|
| 99 |
+
// Keep the same basic timing engine as SPI.
|
| 100 |
+
// Bit-reverse bytes per UG380 Table 2-5
|
| 101 |
+
wire [7:0] pack_data_in_rev={
|
| 102 |
+
pack_data_in[0], pack_data_in[1], pack_data_in[2], pack_data_in[3],
|
| 103 |
+
pack_data_in[4], pack_data_in[5], pack_data_in[6], pack_data_in[7]};
|
| 104 |
+
reg odd=0, icap_clk=0;
|
| 105 |
+
// reg icap_we=0, icap_en2=0; // when were these used?
|
| 106 |
+
reg [7:0] icap_upper_data=0;
|
| 107 |
+
always @(posedge clk) begin
|
| 108 |
+
// if (word2) icap_en2 <= icap_en;
|
| 109 |
+
// if (word3) icap_we <= icap_en2 & odd;
|
| 110 |
+
if (word3) icap_upper_data <= pack_data_in_rev;
|
| 111 |
+
if (word & icap_en) odd <= ~odd;
|
| 112 |
+
icap_clk <= subtick[6] & odd & ~word2;
|
| 113 |
+
end
|
| 114 |
+
wire [15:0] icap_wdata = {icap_upper_data,pack_data_in_rev};
|
| 115 |
+
wire [15:0] icap_result;
|
| 116 |
+
wire icap_busy;
|
| 117 |
+
|
| 118 |
+
generate if (xc6slx == 1) begin : ICAP6
|
| 119 |
+
// 16-bit I port (for writing) and O port (for reading)
|
| 120 |
+
ICAP_SPARTAN6 intern(.CLK(icap_clk),
|
| 121 |
+
.CE(~icap_en), // icap_en is active high, CE "pin" is active low
|
| 122 |
+
.WRITE(1'b0), // funny name for a pin where "0" means write
|
| 123 |
+
.I(icap_wdata),
|
| 124 |
+
.O(icap_result), .BUSY(icap_busy));
|
| 125 |
+
end else if (seven == 1) begin : ICAP7
|
| 126 |
+
// see UG953 and
|
| 127 |
+
// https://opencores.org/projects/wbicapetwo by Dan Gisselquist
|
| 128 |
+
wire [15:0] o_padding; // half of the O port not used, since we configure width as X16
|
| 129 |
+
ICAPE2 #(.ICAP_WIDTH("X16")) reconfig(.CLK(icap_clk),
|
| 130 |
+
.CSIB(~icap_en), .RDWRB(1'b0),
|
| 131 |
+
.I(icap_wdata), .O({o_padding, icap_result}));
|
| 132 |
+
assign icap_busy=0;
|
| 133 |
+
end else begin : no_ICAP
|
| 134 |
+
assign icap_result=0;
|
| 135 |
+
assign icap_busy=0;
|
| 136 |
+
end endgenerate
|
| 137 |
+
wire [7:0] icap_result_byte={7'b1010000,icap_busy}; // XXX useless for actually reading data
|
| 138 |
+
|
| 139 |
+
assign pack_read_strobe=word2&running;
|
| 140 |
+
assign pack_read_done=running&(bytes_remaining==0);
|
| 141 |
+
|
| 142 |
+
assign pack_write=pack_read_ready;
|
| 143 |
+
assign pack_write_strobe=word&running;
|
| 144 |
+
assign pack_data_out = icap_en ? icap_result_byte : sr_next;
|
| 145 |
+
|
| 146 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/status.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Packet Badger Status / Progress
|
| 2 |
+
|
| 3 |
+
* 2018-11-02: Input scanner (scanner.v) can properly detect
|
| 4 |
+
Ethernet, ARP, IP, ICMP, and UDP. Makefile includes useful regression tests.
|
| 5 |
+
* 2018-11-13: Simulation constructs working ARP and ICMP echo
|
| 6 |
+
(ping) replies, verified with Linux tap interface.
|
| 7 |
+
* 2018-11-15: Simulation (Linux tap) also gives UDP echo.
|
| 8 |
+
* 2018-11-18: Hardware (SP605) responds to ARP and ICMP echo.
|
| 9 |
+
* 2018-11-20: ARP, ICMP echo, and UDP all work reliably with tap
|
| 10 |
+
using either Icarus or Verilator, and on SP605.
|
| 11 |
+
* 2018-11-23: Responds only to configured set of UDP ports
|
| 12 |
+
* 2018-11-24: Multiplexes between (trivial) UDP port sources
|
| 13 |
+
* 2018-11-28: Documented, tested, and used client interface
|
| 14 |
+
* 2018-12-05: Working mem_gateway, with regression test, confirmed on SP605
|
| 15 |
+
* 2018-12-10: Fixed dropped-packets problem, tested with > 10^8 packets
|
| 16 |
+
* 2018-12-20: Demonstrated functional on AC701/RGMII, synthesizing with XST
|
| 17 |
+
* 2018-12-21: Demonstrated functional on AC701 when synthesizing with Vivado
|
| 18 |
+
* 2019-01-15: Merged into bedrock
|
| 19 |
+
* 2019-03-26: Refactored udp-vpi.c to enable Verilator test of mem_gateway.v
|
| 20 |
+
* 2019-04-29: Demonstrated Tx MAC working on hardware
|
| 21 |
+
* 2019-05-31: MAC supporting TFTP works in simulation
|
| 22 |
+
|
| 23 |
+
Synthesized by XST 14.7 for Spartan-6:
|
| 24 |
+
|
| 25 |
+
| **module** |**LUTs**|**RAMB16**|
|
| 26 |
+
|:-------------------:|:-----:|:--------:|
|
| 27 |
+
| scanner.v | 271 | |
|
| 28 |
+
| construct.v | 192 | |
|
| 29 |
+
| xformer.v | 93 | |
|
| 30 |
+
| ethernet_crc_add.v | 94 | |
|
| 31 |
+
| udp_port_cam_v | 31 | |
|
| 32 |
+
| rtefi_blob.v | 1044 | 2 |
|
| 33 |
+
| gmii_hw_test.v | 1582 | 6.5 |
|
| 34 |
+
|
| 35 |
+
This Verilog code is intentionally portable and standards-based.
|
| 36 |
+
It has been tested using:
|
| 37 |
+
|
| 38 |
+
* verilator 3.900 through 5.032 (including 5.006 in stock Debian 12 bookworm)
|
| 39 |
+
* iverilog 10.1 through 12.0 (including 11.0 in stock Debian 12 bookworm)
|
| 40 |
+
* yosys 0.23 through 0.52 (including 0.23 in stock Debian 12 bookworm)
|
| 41 |
+
* Xilinx XST 14.7
|
| 42 |
+
* Xilinx Vivado 2015.3, 2017.4, 2018.1, 2020.2
|
| 43 |
+
|
| 44 |
+
All the .eps files here are created with and editable by xcircuit.
|
| 45 |
+
|
| 46 |
+
Files in tests/sp605/, tests/ac701/, and tests/kc705/ are only here temporarily;
|
| 47 |
+
eventually they should be constructed by the LBNL/ATG project infrastructure.
|
| 48 |
+
|
| 49 |
+
Next steps, pretty much unordered:
|
| 50 |
+
|
| 51 |
+
* Rename modules, signals, and project
|
| 52 |
+
* Create an instantiation template along with rtefi_blob.v
|
| 53 |
+
* Update documentation
|
| 54 |
+
* Analyze, test, and document limits on p_offset
|
| 55 |
+
* Better force or test that all GMII signals are latched in IOBs
|
| 56 |
+
* Do something with GMII_RX_ER, test
|
| 57 |
+
* Decrement TTL as part of echo loop mitigation strategy?
|
| 58 |
+
* Consider dropping UDP packets with zero data length
|
| 59 |
+
* UDP Rx checksum?
|
| 60 |
+
* Add SPI clients
|
| 61 |
+
* Find help to exercise this on an Altera board
|
| 62 |
+
* Increase minimum number of 0x55 in Tx preamble
|
| 63 |
+
* Hook to allow use of TAP device other than tap0
|
| 64 |
+
* Add monitoring hooks, like packet, byte, and error counts
|
| 65 |
+
* Add authentication option
|
| 66 |
+
* Refactor and rewrite for clarity and reduced LUT count
|
| 67 |
+
* Attach Tx and Rx MAC to a soft core
|
| 68 |
+
* Add IEEE-1588 (PTP) feature to MAC
|
| 69 |
+
* Make optional based on parameters: ARP and ICMP echo
|
BerkeleyLab_Bedrock/badger/test_tx_mac.v
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module test_tx_mac #(
|
| 2 |
+
parameter mac_aw=10, // 16-bit words
|
| 3 |
+
parameter big_endian=0
|
| 4 |
+
) (
|
| 5 |
+
input clk,
|
| 6 |
+
// There is an implied DPRAM _not_ included in this module.
|
| 7 |
+
// These ports access its read port, with assumed 1-cycle latency
|
| 8 |
+
// The packet length is stored as the first word of a buffer.
|
| 9 |
+
// Endian-ness is configurable.
|
| 10 |
+
output [mac_aw-1:0] host_addr,
|
| 11 |
+
input [15:0] host_d,
|
| 12 |
+
// Request from host to transmit a packet, already converted to
|
| 13 |
+
// (or at least usable in) our clk domain.
|
| 14 |
+
// OK to just latch buf_start_addr on one host clock cycle,
|
| 15 |
+
// and raise the start signal on the next.
|
| 16 |
+
// Also OK to construct buf_start_addr with a handful of
|
| 17 |
+
// static 0 at the lsb (representing granularity of buffer starts),
|
| 18 |
+
// could save a few registers in that clock domain crossing.
|
| 19 |
+
input start,
|
| 20 |
+
input [mac_aw-1:0] buf_start_addr,
|
| 21 |
+
output done, // 4-phase handshake with start signal
|
| 22 |
+
// Connection to precog module
|
| 23 |
+
output req,
|
| 24 |
+
output [10:0] len_req, // can represent 1 MTU, in octets
|
| 25 |
+
// Connection to output multiplexer (xformer.v)
|
| 26 |
+
input strobe,
|
| 27 |
+
output [7:0] mac_data
|
| 28 |
+
);
|
| 29 |
+
|
| 30 |
+
reg [mac_aw-1:0] buffer_point; // in words
|
| 31 |
+
reg [2:0] mode=0;
|
| 32 |
+
reg [10:0] len_req_r=0;
|
| 33 |
+
reg req_r=0, done_r=0;
|
| 34 |
+
reg odd_octet=0;
|
| 35 |
+
wire even_octet = ~odd_octet;
|
| 36 |
+
// There's a total of two cycles latency from setting buffer_point
|
| 37 |
+
// to being able to use the result of reading that DPRAM entry.
|
| 38 |
+
always @(posedge clk) case (mode)
|
| 39 |
+
0: if (start) begin
|
| 40 |
+
mode <= 1;
|
| 41 |
+
buffer_point <= buf_start_addr;
|
| 42 |
+
end
|
| 43 |
+
1: begin
|
| 44 |
+
mode <= 2;
|
| 45 |
+
buffer_point <= buffer_point + 1;
|
| 46 |
+
end
|
| 47 |
+
2: begin
|
| 48 |
+
mode <= 3;
|
| 49 |
+
len_req_r <= host_d[10:0];
|
| 50 |
+
odd_octet <= 0;
|
| 51 |
+
req_r <= 1;
|
| 52 |
+
end
|
| 53 |
+
3: if (strobe) begin
|
| 54 |
+
odd_octet <= ~odd_octet;
|
| 55 |
+
buffer_point <= buffer_point + even_octet;
|
| 56 |
+
len_req_r <= len_req_r-1;
|
| 57 |
+
if (len_req_r == 1) begin
|
| 58 |
+
mode <= 4;
|
| 59 |
+
done_r <= 1;
|
| 60 |
+
req_r <= 0;
|
| 61 |
+
end
|
| 62 |
+
end
|
| 63 |
+
4: begin
|
| 64 |
+
if (~start) begin
|
| 65 |
+
mode <= 0;
|
| 66 |
+
done_r <= 0;
|
| 67 |
+
end
|
| 68 |
+
end
|
| 69 |
+
endcase
|
| 70 |
+
|
| 71 |
+
assign host_addr = buffer_point;
|
| 72 |
+
assign len_req = len_req_r;
|
| 73 |
+
assign mac_data = (odd_octet^big_endian) ? host_d[15:8] : host_d[7:0];
|
| 74 |
+
assign done = done_r;
|
| 75 |
+
assign req = req_r;
|
| 76 |
+
|
| 77 |
+
endmodule
|
BerkeleyLab_Bedrock/badger/tests/ac701_rgmii_test.tcl
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
source "badger.tcl"
|
| 2 |
+
set build_id "ac701_rgmii_test"
|
| 3 |
+
set chip_id "xc7a200t-fbg676-2"
|
| 4 |
+
set top_module "rgmii_hw_test"
|
| 5 |
+
set verilog_defines [list "CHIP_FAMILY_7SERIES" ]
|
| 6 |
+
badger_build $build_id $chip_id $top_module $verilog_defines
|