Commit Graph

112 Commits

Author SHA1 Message Date
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 ace0932340 icE1usb fw: Use helper functions to derive config value from struct
Just from this patch, it's not clear why this is better, but
it makes things a bit cleaner in upcoming patches

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I4c75bb4eb20c1d1aaa1695e95bdf0417bbf3bf76
2022-01-10 12:41:49 +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 5e3fbfe217 icE1usb fw: Warn in case of unused variables
Helps spot left overs from cleanups

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ib5a0b24bace3b9566d974382c90f4153734fc3f3
2022-01-09 19:27:55 +01:00
Sylvain Munaut b4d25799ff icE1usb fw: Update list of debug commands
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I25c3d1db5d9ffae1cf4de83aed89b6394d032dd8
2022-01-09 19:27:55 +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 0abe343d92 icE1usb fw: Don't prefill feedback
This prevents inlining of the code, and is completely
unecessary.

 (1) It will be filled a bit later
 (2) We don't have any meaningful feedback to provide anyway

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I6e97bc79d1fe50950bb1f7cd71d8c428e928d4ae
2022-01-09 19:18:08 +01:00
Sylvain Munaut 41c98b6b67 icE1usb fw: Add multi-port support in USB code
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I134410b542461c34339baa8d9120a5c86fc35d46
2022-01-09 19:18:08 +01:00
Sylvain Munaut 1d98709ff1 icE1usb fw: Tweak descriptors in preparation for dual port support
In dual port mode we can't have 388 bytes wMaxPacket size, that's
too much reserved bandwidth.

So we dial that back to 292 which is the minimum we can use. We need
4 bytes for header, then 256 byte of nominal transfer size then 32
more byte for potentially one more frame than nominal to compensate
differences between E1 clock and USB clock.

We obviously need to adapt the code filling up the packets to respect
that more restricted size ...

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I700adeb909e7955db0d15c6e2beade3d38b21e01
2022-01-09 17:21:04 +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 436b775e03 icE1usb fw: Expose the ticks from multiple E1 ports in misc.{c,h}
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I4dfdeecb6d3a25025095cd017ebbf74aee41c8b2
2022-01-09 17:21:04 +01:00
Sylvain Munaut 8f31a9e84c icE1usb fw: Use 'int' as the default type for port index
No benefit to use uint8_t and for consistency with later patches,
use 'int' here too.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I50a76476af844acf20436b9d410cb917b723590d
2022-01-09 17:21:04 +01:00
Sylvain Munaut d108dfb9af icE1usb fw: Fix computation of received E1 frames from USB
Several issues :

 - The reported length includes the CRC so it's minus 6 and
   not minus 4. (2 for CRC, 4 for header)

 - Cast length to int to make it signed so the minus works

 - If the packet is empty, this would be negative (no header),
   underflow, and then try to submit a giant number of frames
   to the E1 hardware

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ib754e460290fe2e1551a0090e30a51846131d07d
2022-01-09 17:21:04 +01:00
Sylvain Munaut ff44f147f6 icE1usb fw: Use the interface/endpoints #define in usb_e1.c
Avoid hardcoded ids everywhere. This also prepares a bit for
multi-port support in the future.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I89c86ac6afd52dd19e3383b38c3311276a090d50
2022-01-09 17:21:04 +01:00
Sylvain Munaut 0f40ee0e52 icE1usb fw: Vendor requests to other interface than 0 are not errors
They might be used somewhere else ... just don't handle them, but
let someone else potentially do it.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ie1bce4565d14d6635d4a32c2a08f64728132a75e
2022-01-09 17:21:04 +01:00
Sylvain Munaut 0749d576d3 icE1usb fw: Remove useless variable in main loop
Left over from early testing code ...

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I242bbcd42ba96f56bf12bbe57537f3a72a44767b
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
Sylvain Munaut 8a5a9d4dfb icE1usb fw: Use #define's in descriptors for interface/endpoints ID
This way they can be used in other parts of the code more easily.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I565d9a43bc26b99bc385b46522e7da6a207b2412
2022-01-09 17:21:04 +01:00
Sylvain Munaut 3c3ae79241 icE1usb fw: Set wDetachTimeout to 0 in DFU descriptor
It was pointed out that this should be 0 since we trigger
detach ourselves, we don't need a bus reset.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Id7051ce00863c03e3498f4bab0a7124938e197c0
2022-01-09 17:21:04 +01:00
Sylvain Munaut 9674436e2a icE1usb fw: Cleanup USB code a bit
Some of it was written before some of the helpers were provided
by the no2usb code and was never update. So instead of manually
setting up a bunch of stuff we make proper use of some of the provided
helpers.

Side effects:

 - We recall e1_init(0,0) when enabling which happens to work
   around a bug ... proper fix coming later.

 - The 'dual BD' config for EP 0x81 and 0x83 is fixed. It didn't
   matter before since we overwrote it anyway, but now it's used
   and so needs to be correct.

 - The descriptors don't have the isoc endpoints at all in the
   "OFF" alt setting.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I33c92896acfba023abe0152d63dff3afe43b53cd
2022-01-09 17:21:04 +01:00
Sylvain Munaut 7cfe017047 common fw: Add a 'panic' handler
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ice3f338abfe3d361da875c3233b8a052bd6aa2c2
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
Sylvain Munaut d376b2e852 fw/ice40-riscv: Remove usb_ep_boot manual declaration
It's now properly declared in the stack header

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Id2fd50c04a8d8781ad8b94e12ba9f469777482d1
2021-05-31 19:22:22 +02:00
Sylvain Munaut b9d9363d91 fw/icE1usb: Adapt the CDC descriptors to new structure from no2usb
Those are actually disabled right now, but since the submodule got
updated and the protocol struct/defines changed, this updates them
anyway so you can uncommend/enable them without causing a build
failure

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I1895702eac9c6c392f24327b12f9ba3651e3249a
2021-05-31 14:03:44 +02:00
Harald Welte e6b0fe8377 icE1usb fw: un-configure E1 when altsetting 0 is selected.
So far we started on altsetting 0->1 transition, but we didn't stop
on the inverse 1->0 which typically happens when the host software
(osmo-e1d) stops.

Closes: OS#4676
Change-Id: I8e4817f68d8893ab2dc98fe93ce9a673e209ca63
2021-01-05 23:25:38 +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 2df1f805a6 icE1usb fw: Include E1 frame number in Rx USB header
This should enable the host to detect discontinuities, and also know
when a multiframe starts.

Related: OS#4674
Change-Id: Ie0688647c56ebfc2e08de44f8ec569e1c2cd6a28
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
Harald Welte 3255b74187 firmware: Build firmware files with auto-generated version numbers
This resembles what we do for other firmware targets, such as simtrace2,
osmo-ccid-firmware, etc.

As we have multiple different firmware, hardware, gateware projects in
this repository, and they each may have separate tags, we now require
that there are project specific tags.  So for example, tags with a
prefix of icE1usb-fw for the firmware versions.

symlinks for easy use by scripts etc. are generated, always pointing to
the last-built versioned filename.

Change-Id: Ia308587e36a79c27fdb285e369a9c921ee65995f
2020-12-17 13:20:51 +01:00
Harald Welte ae2c89e19e firmware: Rename fw_app.bin to icE1usb-fw.bin / e1_tracer-fw.bin
This is clearly much more descriptive, and avoids mixing up firmware
files for different boards

Change-Id: I319edb76dd74be6904395692ab1599fb8f1f9065
2020-12-17 13:20:51 +01:00
Harald Welte 2b7dadf73e cosmetic: comment spelling
Change-Id: I89e2ae1478688929a42c94c8279ebff1b3a6cd88
2020-12-15 08:48:26 +01:00
Harald Welte c827185cc9 icE1usb: Mark some private functions as 'static'
Change-Id: Ie9808bb2fe264e9a3fa09168bfde57837b77d291
2020-12-14 13:48:09 +01:00
Sylvain Munaut 4d9a04e265 firmware/ice40-riscv: Enable more build warnings
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I99fad45e3aa9accbacaf020b1f5f93aa4b1d4950
2020-10-29 13:27:19 +01:00
Sylvain Munaut 9067392724 firmware/ice40-riscv/icE1usb: Remove a obsolete debug command
This doesn't even do anything on this SoC ...

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ia57674dcfb578b3a68845a9719aaad7ee285dc76
2020-10-29 13:26:38 +01:00
Sylvain Munaut 632a3008b3 firmware/ice40-riscv: Add usb_e1.h
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ica42b00d3f6ae910e2b4711b7eade2492b3cebfb
2020-10-29 13:25:45 +01: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 5e0217ea72 firmware/ice40-riscv/e1-tracer: Fix e1_tick_read()
This was broken when moving the design to non-hacked multi channel
E1.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I5e7ce22935609bc64333e2d5c310eb7493555a93
2020-10-29 13:24:02 +01:00
Sylvain Munaut c704c0704e firmware/ice40-riscv/e1-tracer: Remove CDC descriptors
This was never used and doesn't really belong here, this was just
an example descriptor in the original firmware this is based on.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ic72c991eb7a566b227484c7cde2c305d58202219
2020-10-29 13:22:55 +01:00
Sylvain Munaut f0d1218403 firmware/ice40-riscv/e1-tracer: Remove unused declaration of vio_set
This is a remanence of old firmware of the icepick on which that
design is based on.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I0bc27da4faa91de983cd5f355553ecaa13754266
2020-10-29 13:20:16 +01:00
Sylvain Munaut 46d6b412f5 firmware/ice40-riscv: Create a reboot() function
instead of direct access to registers.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Iaee092c5ef651f0350b3f46386ed79fdbe06afcb
2020-10-29 13:19:05 +01:00
Sylvain Munaut 4ea7d27764 firmware/ice40-riscv: Update no2usb core and fixup for API changes
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ia6bda410e2529858cb86827e186bb099b9b87799
2020-10-29 13:17:11 +01:00
Sylvain Munaut bc59615ebc firmware/ice40-riscv: Minor cleanup in SPI xfer routine
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I2da662af8279746f0f3788a9a0a5cfdfe9dc9f99
2020-10-28 21:59:29 +01:00
Sylvain Munaut c5f3f77909 firmware/ice40-riscv: Use const data ptr for spi program fn
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I28b826b7a559ffccccdfa7c6e289a715ab1a4a01
2020-10-28 21:58:57 +01:00
Sylvain Munaut 5e86047024 fw/icE1usb: Update to support production hardware
Also default build to it since very few people would want to build
firmware targetted to the prototypes ...

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2020-09-15 22:20:21 +02:00
Sylvain Munaut 035e247bf0 fw/ice40-riscv: Fix reboot to bootloader
Address was from previous gateware ...

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2020-09-15 22:09:53 +02:00
Sylvain Munaut 1ac458f5fa fw/icE1usb: Reorganize fields in misc peripheral
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2020-09-15 22:09:10 +02:00
Sylvain Munaut c1d117b6de gateware/firmware: Match rx/tx tick order in register with doc
The documentation always had the rRX tick in the LSB which
is consistent with having the RX units before TX.

They can be read as 16 bit value anyway so there isn't any
performance impact.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2020-09-15 21:57:52 +02:00
Sylvain Munaut f5d7bf2480 fw/e1-tracer: Import firmware for the E1 tracer board
Some more code could probably be unified with the "normal" usb E1 adapter
to both reduce code duplication but also offer 'sniff' function to the
E1 adapter.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2020-09-14 10:56:49 +02: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
Sylvain Munaut 26bc4659af firmware/ice40-riscv: Import common parts to all iCE40/RISC-V firmwares
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2020-09-14 10:56:49 +02:00