Commit Graph

8 Commits

Author SHA1 Message Date
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 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 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 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 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 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