Commit Graph

103 Commits

Author SHA1 Message Date
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
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 be2bded61e Add some more files to gitignore
Some of the ignores were not updated properly when reworking the
Makefile. Also add tags.

Fixes: 6af697b ("Initial support for post-placement simulation")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-05 12:52:57 -04:00
Sean Anderson b76a280e2c Add licenses
Looks like I forgot to add these earlier.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-05 12:50:12 -04: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 20dca056ad Fix building tests
The wrong module to dump signals was included; fix it.

Fixes: 3ec1f4d ("Automatically dump signals")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-05 12:37:18 -04:00
Sean Anderson 38892fa3d7 Clean/ignore log directory
Clean out the log directory like the rest, and ignore it in git.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-05 12:37:18 -04:00
Sean Anderson 4b55a822ab Rename test targets
The dependencies for the test target never got updated when some modules
were renamed. Fix this.

Fixes: 494ef2a ("pcs: Split into rx/tx")
Fixes: cf0aed4 ("pmd_io: Rename to pmd_dp83223_rx")
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 ece7d6c619 descramble: Pass through scrambled_valid
Even when signal_status is low, we should still generate data. This
keeps the PCS processes moving along.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-05 11:54:39 -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 ec08287853 scrambler: Fix wrone assignment type
This process uses the wrong assignment type. Fix it.

Fixes: 12a4678 ("Add (de)scrambling support")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-11-02 00:16:43 -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 63006ca9c0 pmd_dp83223: Delay signal_status by an additional clock
When increasing the delay for the recieved data, I forgot to increase
the delay for the signal status as well. Fix this.

Fixes: c02d3f3 ("pmd_io: Calculate wraparound based on state and not state_next")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-30 22:02:32 -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 c02d3f3ad0 pmd_io: Calculate wraparound based on state and not state_next
Basing the wraparound calculation on state_next is causing problems for
timing. Do it with the state calculations instead. We need to add
another cycle of latency to make this work, since we can't output the
data correctly without knowing the wraparound.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-30 20:58:18 -04:00
Sean Anderson 2d8caf575d pmd_io: Use single-ended inputs
These inputs were incorrectly marked as LVDS, which was causing problems
for placement. Make them single-ended.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-30 20:57:04 -04:00
Sean Anderson 548bf79f55 descramble: Determine relock_next from idle_counter directly
When writing this initially, I tried to remove some duplicate
conditionals by working with idle_counter_next. However, yosys isn't
smart enough to rewrite the calculation in terms of idle_counter, so do
it ourselves. This breaks up the critical path.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-30 20:53:18 -04:00
Sean Anderson 1b47635644 descramble: Use lsfr counter for unlock_timer
The critical path often includes the unlock timer. Switch to an lfsr
implementation. This saves around 20 LUTs and reduces the critical path
from the carry chain (and the or reduction) to just the and reduction.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-30 20:50:18 -04:00
Sean Anderson 3ec1f4d77d Automatically dump signals
While manually dumping signals with a macro works OK for standalone
modules, it doesn't work when multiple modules are included. Instead,
create a second top-level module to dump signals. Inspired (once again)
by [1].

[1] https://github.com/steveicarus/iverilog/issues/376#issuecomment-709907692
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-30 14:20:48 -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 b060eef25e Store synthesis logs
Yosys is very verbose, so I usually run it quietly. However, it may be
usefult to review synthesis logs when debugging.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-16 18:00:02 -04:00
Sean Anderson 6af697b4eb Initial support for post-placement simulation
This isn't really useful for most modules (since the placement info is
if they were the only thing instantiated), but it should be a good base.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-16 17:52:27 -04:00
Sean Anderson 548e5b5b51 Convert all reg assignments to initial
As it turns out,

	reg foo = 0;

is not the same as

	reg foo; initial foo = 0;

but instead is equivalent to

	reg foo; always @(*) foo = 0;

This is rather silly. Convert all existing (lucky) examples to the
second form.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2022-10-16 17:48:43 -04:00
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