Commit Graph

70 Commits

Author SHA1 Message Date
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 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 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 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 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 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 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 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 3b836d3ad0 nrzi_decode: Add reset input
Most other modules in the recieve path are reset when signal_status goes
low. This one didn't, and it was difficult to test because of this. In
particular, we need to ensure that this module behaves correctly when
switching between different bitstreams (such as for loopback).

While implementing this, I found some bugs in the way that nrzi_valid
was handled: it wasn't saved from when the transfer actually happened,
and the data wasn't qualified properly.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-30 18:14:23 -05:00
Sean Anderson 52325f241b Add AXI stream replay buffer
This implements an AXI stream buffer which allows replaying of the first
portion of each packet. The intent is to simplify the implementation of
CSMA/CD. This requires keeping 56 bytes of data to "replay" (slot time
minus the preamble). After these bytes are transmitted, we can only get
late collisions.

We always read from the buffer, as this simplifies the implementation
compared to some kind of hybrid fifo/skid buffer approach. The primary
design problem faced is in determining when it's OK to overwrite the
first byte in the packet. A naïve approach might be to allow overwriting
whenever the slave reads the last byte. However, in the case of a
54-byte packet, we will still need to allow replaying at this point (in
case there is a collision on the last byte). We can't just wait for
m_axis_ready to go high, because that would violate the AXI stream
protocol. To solve this, the slave must assert the done signal when it
is finished with the packet.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-30 18:14:23 -05:00
Sean Anderson f6f3f024e4 Add phy_core
This module integrates the PCS with the descrambler, implements the PMA
(which is just the link monitor), and implements loopback and coltest
functions. This is more of the PCS/PMA, but the descrambler is
technically part of the PMD, so it's the "core" instead.

We deviate from the standard in one important way: the link doesn't come
up until the descambler is locked. I think this makes sense, since if
the descrambler isn't locked, then the incoming data will be gibberish.
I suspect this isn't part of the standard because the descrambler
doesn't have a locked output in X3.263, so IEEE would have had to
specify it.

Loopback is actually implemented in the PMD, but it modifies the
behavior in several places. It disables collisions (unless
coltest is enabled). Additionally, we need to force the link up (to
avoid the lengthy stabilization timer), but ensure it is down for at
least once cycle (to ensure the descrambler desynchronizes).

On the test side, we just go through the "happy path," as many of the
edge conditions are tested for in the submodule tests. Several of those
tests are modified so that their helper functions can be reused in this
test. In particular, the rx path is now async so that we can feed it
rx_data.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-05 12:37:18 -04:00
Sean Anderson 1c37899100 nrzi_encode: Fix test name
The test name has a typo. Fix it.

Fixes: c6f95ce ("Add NRZI support")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-05 12:37:18 -04:00
Sean Anderson 02069bceee pcs: Add false_carrier signal
This adds an explicit false carrier signal. Trying to determine this
condition the MDIO signals is tricky because BAD_SSD can last over
several cycles of CE. To make things easier, add a signal which is high
only once per event.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-05 12:37:18 -04:00
Sean Anderson db30c5f8ba mdio_regs: Add register to enable test modes
This adds a register allowing us to control the test modes of the
descrambler and link monitor.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-02 17:44:37 -04:00
Sean Anderson 7d35e07401 mdio_regs: Add support for counters
This adds support for counters for interesting conditions (disconnects,
PMD phase wraparounds, errors, etc). All the counters are 15 bits
instead of 16, because 16-bit counters have an fmax of 110MHz or so. All
the counters live behind a condition because they ~double the number of
resources used.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-02 17:37:34 -04:00
Sean Anderson f4c2b1eb1f pmd_dp83223: Don't intentionally cause bit errors
On stretches without transitions, we can lose (or gain) a bit, depending
on how the reciever is reckoning. This can cause spurious test failures
when we get especially unlucky. Keep track of our running disparity
(time-wise, not value-wise) and keep perfect time until we get a
transition (or we start moving back in the right direction).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-30 22:14:18 -04:00
Sean Anderson cf0aed4980 pmd_io: Rename to pmd_dp83223_rx
This better reflects that this is an interface intended to be used with
the DP83223. While we're at it, refactor the module to just handle the
the recieve portion.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-30 22:01:35 -04:00
Sean Anderson 494ef2a2a9 pcs: Split into rx/tx
For easier integration, split the PCS into its rx and tx components.
This was already done on the module level, but now they live in separate
files.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-30 21:32:02 -04:00
Sean Anderson 5ac40dbea2 pcs: data_?x -> ?x_data
Rename signals to be properly heirarchal.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-16 18:58:29 -04:00
Sean Anderson bd42aab5d9 descrambler: Rename unscrambled* to descrambled*
The descrambler should descramble, not unscramble.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-16 18:53:47 -04:00
Sean Anderson 2ce7dc016b pmd_io: Align signal naming with other_io modules
This aligns the signal naming with what is used by other modules (IEEE
names for external signals, and something else for internal).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-16 18:39:33 -04:00
Sean Anderson bdbfd4efcd mdio:io: Don't drive mdio as X in testbench
This will mess up the internal logic unnecessarily.

Fixes: dd41839 ("Add MDIO I/O module")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-16 17:37:38 -04:00
Sean Anderson d9602b6f78 Add MII management functions
This adds a module implementing the the MII management functions (the
MDIO regs). For the moment, we just implement the standard registers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-31 12:36:11 -04:00
Sean Anderson ebcb8cc056 mdio: Support
The 802.3.22.2.4.3 requires that the phy not respond to reads of and
ignore writes to unimplemented extended registers. When writing the mdio
module, I expected that such read/writes would not be acked by the
registers. However, that behavior is not especially nice for wishbone
masters which don't expect it. Instead, allow the slave to return an
error instead. We need an extra saved_err variable, since we might not
be able to set bad immediately (when ce is low).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-29 21:25:25 -04:00
Sean Anderson fb751eb7fb mii_io: Add isolation support
The specification requires that the MII be isolated before the STA
clears the BMCR.ISOLATE bit. Add support for this to the MII I/O
modules.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-28 18:43:23 -04:00
Sean Anderson ead545e85e Rename pmd to pmd_io
This better reflects the function of the module (interfacing the
transciever via the I/O pins), and fits better with the naming scheme
used for other I/O modules.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-28 17:25:24 -04:00
Sean Anderson 0c2989b13c Add MII input transmit interface
The actitecture is overall fairly similar to the receive interface,
except that the directions are mostly different. The timing is a bit
easier, since we control the ce signal. Data is sampled one clock before
tx_clk goes high, which is the earliest that it is guarantee'd to be
valid. We could get an extra half-clock by having tx_clk go high at the
negedge of clk, but it's unnecessary at the moment.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-28 17:16:33 -04:00
Sean Anderson e2544d702f Add MII output receive interface
This generates the appropriate output for MII receive signals. Because
we don't have a clock synchronous to the recieved data, we may
occasionally have some cycles which are 32 ns or 48 ns long (instead of
the nominal 40 ns). This distorts the duty cycle to 38% or 58%,
respectively, which is within the specified 35% to 65%. This does change
the frequency to either 31 MHz or 21 MHz, respectively, which *is* a
violation of the spec. This could be avoided by introducing a FIFO to
smooth out any variations in jitter, like what RMII does.

The generation of rx_clk is a bit tricky. We can use a combinatorial
signal for the posedge, since that is what the rest of the logic is
referenced to, However, we need to register the negedge to prevent an
early (or late) ce from modifying the duty cycle.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-28 17:09:51 -04:00
Sean Anderson 27d4c6457e tb: descramble: Expand offset search
If we get very lucky, the descrambler can lock after only 28 bits
(the size of the idle counter). Take this scenario into account when
deciding on the offset.

Fixes: 12a4678 ("Add (de)scrambling support")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-28 12:41:43 -04:00
Sean Anderson dd4183991d Add MDIO I/O module
This module implements the I/O portion of the MII management interface.
The output is delayed by 2 clocks in order to ensure that the external
level shifter has switched directions before we drive it. The latency
increase (around 16 ns) is not consequential, since we have around 300
ns from the rising edge of MDC before MDIO has to be valid.

On the other end, the timing requirements for MDIO driven by the STA are
very lenient (for them); MDIO only has to be valid for 10 ns on either
side of the rising edge of MDC. This effectively means we must sample
MDIO synchronously to MDC (not easy with nextpnr), or oversample by 50x.
Fortunately, we have a 125 MHz clock which the rest of the phty runs off
of. However, this basically makes 10x oversampling with the MII clock
impossible.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-28 12:21:02 -04:00
Sean Anderson f1b345299e Add mdio module
This module implements the MII management interface ("MDIO"), and
translates frames into classic wishbone reads/writes. We use a
"state_counter" to keep track of how many additional bits we expect to
recieve before continuing on to the next field in the frame. We require
a preamble because it prevents ambiguity, and omitting it doesn't seem
to be very popular (seeing as it was removed for c45). Generally, even
if we find an error in the frame, we still procede through the states as
usual. This prevents any spurious reads/writes caused by misinterpreting
an unaligned data stream.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-27 15:59:29 -04:00
Sean Anderson 4646500973 tb: Refactor out ClockEnable
Several interfaces have ce signals. Create a common function for driving
these signals, similar to the Clock function.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-27 13:09:30 -04:00
Sean Anderson 12a4678442 Add (de)scrambling support
This adds support for (de)scrambling as described in X3.263. The
scrambler is fairly straightforward. Because we only have to recognize
idles, and because the timing constraints are more relaxed (than e.g.
the PCS), we can make several simplifications not found in other
designs (e.g. X3.263 Annex G or DP83222).

First, we can reuse the same register for the lfsr as for the input
ciphertext. This is because we only need to record the scrambled data
when we are unlocked, and we can easily recover the unscrambled data
just by an inversion (as opposed to needing to align with /H/ etc).

Second, it is not critical what the exact thresholds are for locking an
unlocking, as long as certain minimums are met. This allows us to ignore
edge cases, such as if we have data=10 and valid=2. Without these
relaxed constraints, we would need to special-case this input to ensure
we didn't miss the last necessary consecutive idle. But instead we just
set the threshold such that one missed bit does not matter.

To support easier testing, a test input may be used to cause the
descramble to become unlocked after only 5us, instead of the mandated
361. This makes simulation go much faster.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-27 13:06:38 -04:00
Sean Anderson c6f95ce26f Add NRZI support
This adds support for encoding and decoding nrzi data.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-24 12:29:09 -04:00
Sean Anderson f18acfc0b0 tb: pcs: Import things explicitly
Instead of using a wildcard, import used members explicitly. This is
more tenable now that we don't have to import all the valids
separately.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-24 12:27:40 -04:00
Sean Anderson 592ba14091 tb: Refactor out with_valids
Parametrizing a test over different methods of generating valid data
will be useful for other tests as well. Refactor it out. We have to bind
valids early in with_valids.test, otherwise we will end up binding
with_valids.valid by reference (causing all tests to use saw_valid).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-24 12:25:07 -04:00
Sean Anderson 15ae994ad6 tb: Fix incorrect valid in send_recovered_bits
At the end of the bitstream, we might not have enough bits for valid=2.
If we don't change it to valid=1, instead of marking an X as valid.

Fixes: d351291 ("Initial commit")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-24 12:18:39 -04:00