Commit Graph

26 Commits

Author SHA1 Message Date
Sylvain Munaut d8f33aa792 icE1usb fw: Fix the E1 shutdown process
So, once BD are submitted to hw, we have to wait for them to get
back, and that's what the SHUTDOWN state is for. Now, this needs
to completete before we can call e1_start() again and so in case
it wasn't done in time, we just busy waited in e1_start().

Problem is that in the absence of a valid signal, the RX side won't
process anything and so we will wait forever.

For the TX side, if we are in remote tick config and we never had
any valid signal, this could also hang.

So we change this. There is actually no need to wait for the shutdown
to complete, we can resume where we left off.

For RX: We use the 'RECOVER' which basically waits for all pending BD
to be done, empty the fifo and auto-restarts. The only "side effect" is
that we'll loose up to 4 multiframe of data at the beginning but the
RX start is async anyway, no guarantee of where we pick up.

For TX: First we empty the FIFO from any data that wasn't already
submitted to the hardware (and is now stale) and we also use the
'RECOVER' state which will wait until the FIFO reaches nominal level
before starting feeding new data. The "side effect" here is we might
TX up to 4 multiframe of old data. Although this is rather unlikely
because the conditions for TX not to have transmitted those before
are unlikely (and hopefully go away completely with OS#5402)

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I3f3de5491e0999f89a63f507fafdc4af8c22c905
2022-01-13 13:19:06 +01:00
Sylvain Munaut 0cc1613f39 icE1usb fw: Update E1 core start/stop procedure
Previously we were just doing a hard reset, calling init again.
And to stop, it was a bit harsh as well, just calling init with
0 as argument, not cleaning pending descriptors and such.

Now, the HW is initialized once and there is proper startup and
shutdown procedure, leaving things in the proper state.

Init of e1 hardware (call to e1_init) is also delegated to usb_e1
since it's that module that handles all state changes and config
so it makes sense it handles init too rather than calling it from
fw_app.c

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I639f90ce3488a1a08e87854e74e0586010264f5d
2022-01-10 14:48:56 +01:00
Sylvain Munaut 9410bdf8dd icE1usb fw: E1 core config update depending on state
Store Rx/Tx config separately so we can change some of the config
bit depending on current state while still keeping what the user
asked for.

Not really used ATM since state is never IDLE, but for future use.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I0b4cbf88abc4af801054ba5d6779dede5649852a
2022-01-10 13:18:19 +01:00
Sylvain Munaut e98c0334ec icE1usb fw: Update LED status even in E1 FSM is in IDLE state
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I82b867c4886c9f34ff685764424d3db9a8303789
2022-01-10 12:46:49 +01:00
Sylvain Munaut 29d82097d7 icE1usb fw: Distinguish between E1 FIFO init and reset
Currently it's called 'reset' but really it's the init because
it sets up the memory allocation and such. We rename that to e1f_init
and introduce a true e1f_reset that only clears the fifo and resets
the pointers

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I425c38e93fb235d5c5fc6f3a5027ac49cf3466d9
2022-01-10 12:44:53 +01:00
Sylvain Munaut 4fd7155e93 icE1usb fw: Reorganize functions in e1.{c,h}
RX before TX for consistency ...

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Idcb1890a3a3f4fd2129f73585c4ce9f8475f1e21
2022-01-10 12:28:28 +01:00
Sylvain Munaut e9fe0dca2f icE1usb fw: Apply config reg field filter to e1_init call
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Id45688fed0533f8d7dbbfd993c93f9ffc4e2d53e
2022-01-10 12:26:20 +01:00
Sylvain Munaut ab75c94cce icE1usb fw: Add _MASK version for multibit fields in config regs
This is a bit cleaner when masking in/out those rather than using
the specific vaue that has all bits set.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: If2ca8efff37cb8fd1f1841656537ea8ad11ef55c
2022-01-10 12:22:41 +01:00
Sylvain Munaut d6737bbf93 icE1usb fw: Disable the yellow led if LOS
There is no remote side alarm if there is no remote-side ...

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I78f43eded5ed6ffde9d86726ccee2b776a3f4675
2022-01-09 19:27:55 +01:00
Sylvain Munaut 2de84f804e icE1usb fw: Better flow regulation mechanism
* FIFO target level :

   - The '8 * 16' makes no sense as the FIFO was 128 so this
     is the "full" case and could never be that high.

   - We tighten up the margin around 5 * 16 which is the "target"
     level for the FIFO

 * FIFO size :

   We also increase the FIFO size to 256 frames. This doesn't
   actually affect latency since the target level is the same,
   but it allows more leeway to recover without data loss in
   case something goes wrong.

 * Ticks :

   We don't bother using ticks ... the current algo wasn't
   working (or rather not doing anything all that useful),
   because the difference between USB clock and E1 clock is
   tiny and measured over 1 ms, it's not meaningful.

   So for the time being we just sent the nominal rate biased
   with the FIFO level to keep it on target and this seems
   to work fine.

   It'd be nice to have a good long term estimate of the rate
   to minimize the jitter, but it doesn't seem to be strictly
   required for operation for now.

 * Misc cleanup :

   Just do all in one function instead of splitting the check
   if BD needs refill and the actual refill.

This gets rid of sporadic 'TX FIFO Overflow' conditions
by properly handling the case where we have a bit too much
data.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ibd3bc9080961cc56093e43ab9a824840e84c24d2
2022-01-09 19:19:14 +01:00
Sylvain Munaut 3da5151569 icE1usb fw: Add multi-port support for e1.{c,h}
Currently all the users of those function just statically use port 0
only.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I17671be65543f5a2bf3d16ba2b5a5081eb38ebdf
2022-01-09 17:21:04 +01:00
Sylvain Munaut 2c0c136b7a icE1usb fw: Misc cosmetic cleanup in e1.{c,h} / usb_e1.c
Moving things around, comments, spacing, ... nothing functional.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Icc2a6ef6b03c89dd92e661a01d219e42dbf7067d
2022-01-09 17:21:04 +01:00
Sylvain Munaut 35856a1d61 icE1usb fw: Don't expose some E1 helper functions globally
Not used anywhere and really shouldn't be

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I1e339d1b8faecffba5f8d73588b376edc7a75a96
2022-01-09 17:21:04 +01:00
Harald Welte 51baa368ce icE1usb firmware: Detect A-bit in TS0; report via USB + LED
Scan over every odd E1 frame TS0 byte to check if the A-bit is set,
indicating a remote alarm.  If so, set yellow LED and report via the
error flags communicated to the host by USB interrupt transfer.

Change-Id: Ic4f57cf79bd32cf75f81ef3073cb8d4a2d1857d8
2022-01-02 12:42:35 +01:00
Harald Welte 805f2cf16e icE1usb fw: Expose error conditions from E1 driver
This will allow the USB interface code to report the errors to the
host PC.

Related: OS#4674
Change-Id: Iba3e00a2b28a2fef6dbd986bfc706c1619c3a3ed
2021-01-05 23:25:34 +01:00
Harald Welte 9469e046f1 icE1usb fw: USB control request handling
This introduces a number of vendor-specific control requests for
configuration of the icE1usb from the host software.

Closes: OS#4675
Change-Id: I9d28566ba21a2a78def5e4a0ba07ecbc4a583aa9
2021-01-05 23:24:32 +01:00
Harald Welte 6add0aa3e4 icE1usb fw: Internal API for configuring E1 rx/tx config register
Related: OS#4675
Change-Id: Ib23f9b99f169ab18d730bcf67b97a7b6bf863e98
2021-01-05 23:24:28 +01:00
Harald Welte 7f74fe6e48 icE1usb fw: Don't store E1_*_CR_*_CLR in variables
Those clear bits are only set once at start-up and then later
explicitly.  They shouldn't be stored with the user configuration
in state variables.

Change-Id: If38e86aefea7f1be4e1ff5a88860f8be593eeedc
2020-12-27 15:16:19 +01:00
Harald Welte f74dad7b60 icE1usb fw: Put E1 IP core register related #defines in e1_hw.h
Related: OS#4675
Change-Id: I6783f473e6bb7dd08a5b5714bdd9b5aac0f28f0d
2020-12-27 14:09:02 +01:00
Harald Welte 5276567b24 icE1usb fw: Use green per-port LED to indicate alignment status
Whenever Rx is aligned, the green LED is permanently on.
Whenever Rx is not aligned, the green LED is blinking.

What's missing is to check for E1 clock ticks and turn the LED off
completely if there are no clock ticks.

Change-Id: I42d53544858dbbbae5206d9a62b08672966c9ebf
2020-12-20 23:20:21 +00:00
Harald Welte daff4f6463 icE1usb fw: Have e1_rx_need_data() optionally return FIFO position
The position indicates where we are in terms of frame and multiframe.

The related code was ported over from e1-tracer.

Related: OS#4674
Change-Id: I9e59d86a2e8f4e85ca84c592438ad79966b49448
2020-12-20 23:20:21 +00:00
Harald Welte 175b37c42f icE1usb fw: Use register bit #define instead of magic number
Change-Id: Ic824ce5a6605c96989fefbf92f365bff618dccb2
2020-12-20 23:20:21 +00:00
Harald Welte a59ef2bb3f icE1usb fw: define e1_data_ptr() using e1_data_ofs()
It's best to compute the offset only at one place and use that
computation elsewhere.

Change-Id: I9a6cce07ea8b6eff1527215de00621da960b0472
2020-12-20 23:20:21 +00:00
Harald Welte 30fc560017 icE1usb fw: cosmetic: more comments in the code
Change-Id: I445bb2f92b6dcfe29ac20109ea2e63efb31051a1
2020-12-20 23:20:21 +00:00
Sylvain Munaut de20fb713d firmware/ice40-riscv: Fix a couple of 'mixed signedness' warnings
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I31343263d7dab88a25254258cef44c6c2ddc730a
2020-10-29 13:24:50 +01:00
Sylvain Munaut bc9f5c4219 fw/icE1usb: Import firmware for the icE1usb and icE1usb-proto boards
Currently only the icE1usb-proto is supported. Adaptation for the
final production hardware is yet to be done.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2020-09-14 10:56:49 +02:00