Commit Graph

188 Commits

Author SHA1 Message Date
Sean Anderson c5fc850587 Makefile: Define ICEPACK
This is necessary for creating bitstreams.

Fixes: 5cf02e9 ("Support building actual bitstreams")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 23:34:10 -05:00
Sean Anderson 165b60b7b2 Makefile: Add some missing modules
Add some modules to test with which were previously missing.

Fixes: b68e131 ("Add a basic hub")
Fixes: 0495ae3 ("Add TX MAC (most of it)")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 23:34:10 -05:00
Sean Anderson 45b134b1b2 Add examples
This adds an example of how to integrate the hub into a design. For the
moment, wishbone is disabled, but I plan to add a uart bridge in the
future.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 23:34:10 -05:00
Sean Anderson 8c0836406e Makefile: Make it easier to build files in other directories
Generally, most things (except .fst files) are independent of
directory. Fix up the few exceptions.
2023-02-20 23:34:10 -05:00
Sean Anderson dfd3d1f3b6 Add .bin to file extensions
Clean up/ignore .bin files.

Fixes: 5cf02e9 ("Support building actual bitstreams")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 23:34:10 -05:00
Sean Anderson 5f8c60518f Makefile: Make it easier to clean other directories
Create a list of extensions to clean, and then use wildcards to remove
the files. This will make it easier to clean other (nested) directories.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 23:34:10 -05:00
Sean Anderson f82fd2cac3 hub/phy_core: Export some status signals
Export some status signals which can be used for LEDs. Hopefully this
will deliver an authentic blinkenlights experience.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 23:34:10 -05:00
Sean Anderson b351beb9a0 Add hub
This adds a basic hub wrapper module which incorperates the core
introduced in b68e131 ("Add a basic hub"). For each port, it
instantiates a phy (itself using a phy_internal wrapper) and an elastic
buffer. A WISHBONE parameter is used to control whether to instantiate a
wishbone interface. When disabled, we just respond to any request with
err. I've ommitted a separate testbench for phy_internal, since it is
much easier to create a smoke test using the hub interface.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 23:34:10 -05:00
Sean Anderson cc29d2050c pmd_dp83223_rx: Don't use SB_IO for signal_detect
The flip-flops internal to the SB_IO can't have initial values and
can't be reset. So before the first clock the data out will be X. This
results in a simulation-synthesis mismatch, as sd_delay will be wrong
for one clock cycle. Fix this by removing the SB_IO cell, as the timing
of this signal isn't critical.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 18:39:58 -05:00
Sean Anderson 83d805bb79 tb: mdio_regs: Export wb_xfer
Convert xfer into a form which can be reused in other testbenches.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 18:39:58 -05:00
Sean Anderson fc3cce02ea Makefile: Retry P&R a few times
P&R can be a bit flakey. Retry a few times to get a good seed before
failing.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-18 22:48:36 -05:00
Sean Anderson 7c9ac42988 Add wishbone mux
This adds a simple wishbone mux. The idea is that each slave gets its
own address bit. This lends itself to extemely simple address decoding,
but uses up address space quickly. In theory, we could also give larger
addres space to some slaves, but currently lower bits have priority. The
testbench is also very simple. Since everything is combinatorial, we can
determine the outputs from the inputs exactly.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-18 22:48:36 -05:00
Sean Anderson afbb64023e tb: Move BIT to util
This function may be useful for other testbenches.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-18 22:48:36 -05:00
Sean Anderson a179ccb9ab tb: hub_core: Remove references to Memory
This class is unused. Remove it.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-18 22:48:36 -05:00
Sean Anderson 3b9efe2211 mii_elastic_buffer: Don't use memory access hack on valid/err
We can already probe the valid/err signals, so we don't need to
explicitly access them.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-18 22:48:36 -05:00
Sean Anderson eb8d854476 Silence warnings when converting memories to registers
There are several places where memories are used for parametrization
purposes, but I intend them to be synthesized to registers. Silence
warnings about them by explicitly annotating these variables.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-18 22:48:36 -05:00
Sean Anderson 0511de1e9c Makefile: Fix synthesis dependencies
Using -s /dev/stdin will add a dependency on it, and /dev/stdin is
always considered newer than the synthesis output. Just use multiple
-p options.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-18 22:48:36 -05:00
Sean Anderson d98e7b3adf Add LED blinker
This module will make it easier to observe internal signals which would
otherwise be too short to see, or would trigger too fast to distinguish.
Continuous triggered will cause blinking, so signals which are expected
to be high for a while (e.g. level-based and not edge-based) should not
use this module.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-18 22:48:36 -05:00
Sean Anderson 16b639aad2 Add MII elastic buffer
In order to move data between MIIs without implementing a MAC, we need
some kind of elastic buffer to bring the data into the transmit "clock
(enable) domain." Implement one. It's based on a classic shift-register
FIFO, with the main difference being the MII interfaces and the
elasticity (achieved by delaying asserting RX_DV until we reach the
WATERMARK). We use a register-based buffer because we only need to deal
with an under-/over-flow of 5 or so clocks for a 2000-byte packet. The
per-stage resource increase works out to 6 FFs and 1 LUT, which is
pretty much optimal.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-12 19:53:44 -05:00
Sean Anderson 5cf02e9490 Support building actual bitstreams
In addition to PNR-ing for per-module, post-placement simulation, we
also want to be able to do PNR for the purposes of generating a
bitstream. Refactor things a bit so we can (mostly) reuse the same
command line.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-22 16:26:35 -05:00
Sean Anderson b68e1312c4 Add a basic hub
This adds a basic clause 27 repeater (hub), mostly for test purposes.
It's effectively just the state machine in figure 27-4 and nothing else
(e.g. no partitioning or jabber detection). This is surprisingly simple.

Unfortunately, yosys doesn't allow memories in port declarations, even
for systemverilog. This complicates the implementation and testbench,
since we have to do the slicing ourselves. This is particularly awful
for the testbench, since

	module.signal[0].value != module.signal.value[0]

and module.signal can't be indexed by slices, and module.signal.value is
big endian (ugh ugh ugh). There is no clean solution here.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-21 17:39:25 -05:00
Sean Anderson 798968d3d6 axis_mii_tx: Add support for half duplex
This adds support for half-duplex. This is mostly done by predicating
col and crs on half_duplex. In one place we need to go to IPG_LATE
directly (although we could go to IPG_LATE like FCS with no loss of
standard compliance).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-14 00:08:38 -05:00
Sean Anderson 2fd6dedddb Fix failing tests due to floating point imprecision
get_sim_time can return floating point values. This will cause tests to
fail since there is an epsilon of error. Fix this by timing things in
steps (which is always an int).

Fixes: 0495ae3 ("Add TX MAC (most of it)")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-14 00:05:50 -05:00
Sean Anderson e59e34db93 tb: Fix reset occasionally failing
We might not release rst synchronously if clk was already high. Fix this
by forcing clk to z.

Fixes: 19f2f65 ("axis_mii_tx: Add reset")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-14 00:05:35 -05:00
Sean Anderson 43612337e4 axis_mii_tx: Don't reset mii_txd
It's not valid anyway.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-13 23:35:23 -05:00
Sean Anderson 11bb9651c0 Use separate process for non-resetting registers
Including registers which are not reset in an asynchronous reset process
causes active-low clock-enable flip-flops to be synthesized. This is an
unusual configuration, incurs overhead, and isn't what we wanted to do
anyway. Use a separate process.

While we're at it, sort the bottom half of the if to match the top.

Fixes: 19f2f65 ("axis_mii_tx: Add reset")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-13 23:13:12 -05:00
Sean Anderson 536bdd86bd axis_mii_tx: Delay error handling by one cycle
The 2 ns delay when reading from a BRAM makes it hard to close timing,
since buf_err affects the state machine. Address this by not acting on
errors for a clock cycle. We will output bad data for a cycle, but we
are going to corrupt the FCS anyway so it doesn't matter. We also have
to check for errors in the PAD/FCS states, to ensure they don't slip
past.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-11 17:32:50 -05:00
Sean Anderson 01ff073916 tb: axis_mii_tx: Test one-cycle error
Ensure we transition properly even if buf_err is only high for one
cycle.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-11 17:31:42 -05:00
Sean Anderson 4746b3b6cd tb: axis_mii_tx: Test underflow rather than err with collision
If we ever see an error, we shouldn't retry if we get a collision at the
same time, as we will just have to jam next time. Test for this case
instead.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-11 17:27:35 -05:00
Sean Anderson a3ae038f4f tb: axis_mii_tx.py: Rework test_underflow
This test has a lot of duplication, which makes it harder to modify.
Stick most of it in a loop.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-11 17:26:20 -05:00
Sean Anderson 68751229a0 tb: axis_mii_tx: Forward keyword arguments to send_packet
This makes it easier to add additional arguments.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-11 17:25:52 -05:00
Sean Anderson 34d6a1fd6a tb: axis_replay_buffer: Allow delaying the last byte
Allow delaying the last byte to make it easier to exactly time when the
MAC sees the byte. This way, we can test to ensure that everything works
even when valid is only high for one cycle. We can't change signals
once valid goes high, so this is the only way to ensure this kind of
timing.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-11 17:20:12 -05:00
Sean Anderson 69ddcc388c tb: axis_replay_buffer: Don't delay on last-sent byte
We don't need to delay after sending the last byte, and it makes it more
difficult to time subsequent packets correctly.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-11 17:18:46 -05:00
Sean Anderson aba4fb10c2 axis_mii_tx: Simplify backoff
We only care about backoff when state=BACKOFF. We can simplify the
calculation by defaulting to loading lfsr into backoff, and special
casing things for state=BACKOFF.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-11 00:52:51 -05:00
Sean Anderson 19f2f656cd axis_mii_tx: Add reset
Yosys doesn't optimize FSMs without resets. Add one so ours gets
optimized.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-10 23:56:04 -05:00
Sean Anderson 23913a6b77 axis_mii_tx: Remove some initial values
These signals are initialized (usually by IPG) before they are used.
Remove their initialization.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-10 00:24:44 -05:00
Sean Anderson 0495ae377c Add TX MAC (most of it)
This adds the transmit half of a MAC, supporting 100M and half-duplex.
It's roughly analogous to the axis_(x)gmii_tx modules in Alex
Forencich's ethernet repo. I've taken the approach of moving all state
into the state variable. All decisions are made once and have a
different state for each path. For example, instead of checking against
a "bytes_sent" variable to determine what to do on collision, we have a
different state for each set of actions.

This whole module is heinously complex, especially because of the many
corner cases caused by the spec. I have probably not tested it nearly
enough, but the basics of sending packets have mostly had the bugs wrung
out.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-09 21:05:31 -05:00
Sean Anderson 1f925d39ff tb: axis_replay_buffer: Export send_packet
This function is useful for testing other AXI stream components as well.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-09 21:05:01 -05:00
Sean Anderson 6b2eb4d27c tb: pcs_rx: Allow err to be optional
The downstream TX side of the MII is almost the same as the upstream RX
side of the MII. However, MACs may never generate TX_ER, so I will be
leaving it out. TO allow testing this, make the err signal optional.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-09 21:02:35 -05:00
Sean Anderson d72a7b7e1e Add LFSR
Add an LFSR library. It will be used to calculate CRCs (for now).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-09 21:01:27 -05:00
Sean Anderson 83216ea1e9 scramble: Fix initial lfsr value
I was missing a bit.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-09 20:51:59 -05:00
Sean Anderson fb588994b7 tb: phy_core: Fix col/crs detection
Detecting non-clock signal edges with RisingEdge and FallingEdge is not
very robust, and is recommended against. Track edges manually.

Fixes: f6f3f02 ("Add phy_core")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-09 20:50:00 -05:00
Sean Anderson aa4ccf07c0 phy_core: Remove unused imports from testbench
These are not used. Remove them.

Fixes: f6f3f02 ("Add phy_core")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-09 20:40:02 -05:00
Sean Anderson 3902e8f77a pmd: Export check_bits from testbench
I forgot to export this function when reusing it.

Fixes: 2eac757 ("Add DP83223-based PMD")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-09 20:38:52 -05:00
Sean Anderson 5b3c350581 pmd: Initialize sd_delay
Although the least-significant bit of sd_delay is driven by an SB_IO (if
we are synthesizing), the other bits need to be initialized.

Fixes: d8ce165 ("pmd: Delay signal_status/detect until data is valid")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-09 20:31:39 -05:00
Sean Anderson acfd5f62d2 replay_buffer: Fix s_ptr passing m_ptr
The condition for determining s_axis_ready only looks at whether we are
currently full, not whether we will be full on the next cycle (which is
what matters). Make it take into account whether we are going to
increment s_ptr during the current cycle. Also increase the ratio to
ensure we trigger this case, as a ration of 2 doesn't make the slave
slow enough to catch this.

Fixes: 52325f2 ("Add AXI stream replay buffer")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-01-02 18:47:07 -05:00
Sean Anderson 91ab3b40ce replay_buffer: Fix
If the lower bits of m_ptr is the same as s_ptr when we get s_axis_last
(that is, we are full), then we will immediately end (since m_ptr will
equal last_ptr). Fix this by including all of s_ptr in last_ptr.

Fixes: 52325f2 ("Add AXI stream replay buffer")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-12-24 23:46:35 -05:00
Sean Anderson 040016bd44 phy_core: Simplify collision logic
This mildly simplifies the collision logic.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-30 18:14:23 -05:00
Sean Anderson 2eac757fd7 Add DP83223-based PMD
This adds the integrated PMD module to be used with the DP83223. It
contains NRZI en/decoding as well as the I/O interfaces. The rx I/O was
added a while back, and the tx is just the I/O cell.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-30 18:14:23 -05:00
Sean Anderson f50f5b688f Makefile: Sort modules
This will make adding new modules easier.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-30 18:14:23 -05:00