Commit Graph

59 Commits

Author SHA1 Message Date
Sean Anderson 2832c79ff0 pmd_io: Switch to single-ended tx signal
The singal-ended to differential conversion will be done by the
transceiver (by the ECL interface circuit).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-16 17:42:17 -04:00
Sean Anderson ab341eca0e mii_io_rx: Drive all signals in all branches
This avoids some edge cases with if statements and default values.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-16 17:40:44 -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 2ec039f49a mdio_io: Don't drive mdio_io in second process
This pin is already driven in the I/O process(es).

Fixes: dd41839 ("Add MDIO I/O module")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-16 17:36:40 -04:00
Sean Anderson 67cf4100c6 descrambler: Break up locking logic
This (un)locking logic was on the critical path. Break it up into
multiple parts to allow achieving our desired clock frequency.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-16 17:27:08 -04:00
Sean Anderson 42c1e93338 Rename *post* targets to *synth*
The post here originally stood for post-synthesis. To add support for
post-placement simulation and reduce ambiguity, rename these targets to
*synth*.
2022-09-04 17:14:45 -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 4cc574048d mdio_io: Use localparams for states
These states are not user-modifyable, so make them local.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-29 21:36:24 -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 fe908de1f1 pmd: Consolidate initial assignment
We don't have to use a separate initial statement when declaring initial
values.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-28 12:21:02 -04:00
Sean Anderson 050ecaade6 pmd: Fix wrong type of assignment
This process used the wrong type of assignment. Fix it.

Fixes: 1d65661 ("Add pmd")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-28 12:21:02 -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
Sean Anderson 6800b85a85 tb: Move print_list_at/compare_lists to util
These functions will be useful for other tests. Refactor them out into
utility functions.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-24 12:16:43 -04:00
Sean Anderson 64eb5f9dd8 tb: pmd: Add copyright notice
I forgot to do this in the initial commit.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-24 12:14:29 -04:00
Sean Anderson cbbdbeef1c pcs: Assert CRS after TX_EN sooner
24.6.1 requires that CRS goes high fewer than 4 cycles after TX_EN goes
high. This means we need to assert tx when we enter then START_J state,
not when we actually transmit a /J/. This also has the upside of
simplifying the logic a bit.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-24 12:10:52 -04:00
Sean Anderson 86aee33477 Use MODULE variable for tests
Instead of listing out tested modules each time, use a variable.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-24 12:10:07 -04:00
Sean Anderson 50c1080ba4 Support colorized output with -O
Using -O allows grouping job output, which is helpful when output would
otherwise be interleaved (such as when running tests). However, it also
means that there is no tty attached to the job, resulting in cocotb
automatically turning off color. Detect whether we have a tty during the
parsing phase, and force color output if we do. Technically this should
probably take into account the existing value of COCOTB_ANSI_OUTPUT, but
I don't use it normally.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-24 12:07:25 -04:00
Sean Anderson 897326dbdb Move default_nettype/timescale declaration to common.vh
We will need this in every verilog file, so consolidate things a bit. In
terms of timescale, we need to modify the post-synthesis verilog
generation a bit in order to avoid the module's timecale being
inadverdently overwritten.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-24 12:04:10 -04:00
Sean Anderson 799aeb92d6 Ignore post-synthesis verilog
These files are build artifacts. Ignore them.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-21 12:36:36 -04:00
Sean Anderson 1e8b5adc42 Make testbenches a module
This makes it easier to import things

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-21 12:36:28 -04:00
Sean Anderson c1301ca31a tb: Break out the core of pcs_send_codes into its own function
The PMA also has to deal with "recoverd bitstreams" (that is, inputs which
can have 0, 1, or 2 valid bits). Export the core of pcs_send_codes into its
own function, as it is useful for generating these signals.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-08 00:23:55 -04:00
Sean Anderson fec8a0a9f6 tb: pcs: Don't convert codes to list in pcs_send_codes
This does nothing (especially since we immediately create an iterator)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-08 00:11:58 -04:00
Sean Anderson fd7673743d tb: pcs: Don't revert to idle after pcs_send_codes
Since 0153975 ("tb: pcs: Send packet spacing packets immediately"), we
have never allowed pma_data_rx to remain idle. There's no need to supply
a default value.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-08 00:08:09 -04:00
Sean Anderson 03715d4a83 pcs: rx: Only flush on state change
The PCS state machine is evaluated every cycle, but its outputs are only
registers when the rx_bits module indicates. However, the flush signal
is not registered and is instead combinatorial. Although it's OK to
evaluate the other outputs every cycle, we should only indicate if we
are actually going to change state.

Fixes: d351291 ("Initial commit")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 22:08:09 -04:00
Sean Anderson f8bb110caa tb: pmd: Allow a larger range for alignment
If we get a run of 1s (or 0s) at the start of the stream, it may take a
while for us to align. Increase the alignment range. Additionally, from
testing, it appears that negative ranges are never used. Just start at
0.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson e65903456b tb: pmd: Avoid waiting on a zero-delay timer
According to cocotb, this is not supported by all backends.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson 0c5f7fa905 tb: Parametrize rx tests
In the recieve tests, the harness often has a choice of how fast to feed
data to the module. Up to this point, we have always used the same
strategy (typically random), even when multiple strategies were used
when writing the test. Add parametrization to test different strategies
in each test run. The timing decorator is taken from the cocotb source,
since we can't pass parameters to cocotb.test directly any more.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson 6ffb3481fe Add post-synthesis simulation support
This adds support for running testbenches post-synethesis. Simulating
this way should (hopefully) catch most synthesis/simulation mismatches.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson 6d7847c35f common: Add levels parameter to DUMP
This adds a levels parameter to DUMP, allowing dumping just the
top-level signals, instead of the whole hierarchy. This is helpful for
post-synthesis simulation, where all sub-modules are primitives (with
their inputs and outputs already available at the top level).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson 5e1dabf601 tb: pmd: Add helper for printing data
This adds a helper for printing input/output serial data. Early errors
might not have had the offending bits printed, since slicing
doesn't work with negative indices.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson 16dfe09fba tb: pmd: Wait on signal_status and not valid
valid is an internal signal which isn't available in post-synthesis
simulation. Use signal_status instead, which is externally available.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson 24ec0a4150 tb: pmd: Don't die if pmd.delay is absent
We set this signal for debugging purposes, so don't die if it's absent
(such as in a post-synthesis simulation).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson e79807cdff tb: pmd: Ensure signal_detect starts low
To make sure that pmd.signal_status comes up at the right time, keep
signal_detect low at the start of simulation. We don't need to set
pmd.rx, because X is the default value (or rather Z is, but it's the
same for our purposes).

Fixes: 1d65661 ("Add pmd")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson 8f7c797800 pcs: Fix incorrect assignment type
This is the wrong kind of assignment to use. Fix it.

Fixes: 1d65661 ("Add pmd")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson d8ce1652ae pmd: Delay signal_status/detect until data is valid
The data yielded by the PMD is not really valid until it has made its
way through the pipeline. Delay it until the data is valid. As a side
effect, this should also eliminate any metastability. This is not
necessary for real hardware, but it allows us to to post-synthesis
simulation (where we can't reach in and probe the internal valid
signal).

Additionally, ensure that the state is known by resetting it when we
don't have a signal.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson fafce4df00 pmd: Use correct SB_IO clock names
The clock signals are not named correctly. Fix this.

Fixes: 1d65661 ("Add pmd")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson 01539759d6 tb: pcs: Send packet spacing packets immediately
This avoids a period of Xs on the inputs.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 21:47:21 -04:00
Sean Anderson d27d0089e6 tb: pcs: Wait for rx_ce when receiving errors
Without .value, pcs.rx_ce always evaluates as truthy.

Fixes: d351291 ("Initial commit")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-08-06 15:29:32 -04:00