Commit Graph

221 Commits

Author SHA1 Message Date
Sylvain Munaut c308334de7 icE1usb fw: Add USB control for the GPSDO function
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: If92aa68d8a49349fa0d6d556eec81bbb80be989c
2022-01-13 13:21:29 +01:00
Sylvain Munaut e76b643298 icE1usb fw: Add GPSDO VCXO trimming loop
Rather basic and not super well tested, use with caution

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I5f9ce6621492be967d6a44d31f270e107f3ef686
2022-01-13 13:21:29 +01:00
Sylvain Munaut 70c10f05cf icE1usb fw: Expose the GPS NMEA data as a CDC ACM
Note that this is read-only. We drop all data from the host
because we can't have the host reconfigure the module ...

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ieb6a653ece882c5f90ab27da1bca04c94184dc5a
2022-01-13 13:21:29 +01:00
Sylvain Munaut ef5fe385fe icE1usb fw: Import GPS module driver code
This only initializes the GPS module and keeps track of the
antenna and fix status

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I24811f872fafefc7f8dfaa3028c4288001a87d2f
2022-01-13 13:21:29 +01:00
Sylvain Munaut 7bed9039e4 common fw: Add hexval() utility function
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I724c14d1dee9e268f666030053fbf62ce5e1ba71
2022-01-13 13:21:29 +01:00
Harald Welte 1b89f3bcca icE1usb fw: New ICE1USB_INTF_GET_ERRORS control request
This allows the host driver to obtain the current errors, as they would
normally be reported over the IRQ endpoint.  One important use case for
this is to obtain the initial error state when the driver starts up.

Change-Id: I6301bb23234c66afe083ceb500cff8a40813e8b6
2022-01-13 13:21:29 +01:00
Sylvain Munaut 2c33f6d5bb icE1usb fw: Add support for the ICE1USB_DEV_GET_FW_BUILD control request
This was already defined but not implemented

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Id65734153c92ef87bc9ecf967447e9bf11804f24
2022-01-13 13:21:29 +01:00
Sylvain Munaut caf8cf94e1 icE1usb fw: Move handling of device-wide request in usb_dev.c
We have upcoming ones not related to the E1 interface, so really
it make more sense to not have those in usb_e1.c

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I686916bb2b2cb90e94ac9c595deab19f189fcd49
2022-01-13 13:21:29 +01:00
Sylvain Munaut 00b57625bc icE1usb fw: Add access functions for the 'time' hardware
The hardware has a tick counter (constantly incremented every
cycle) and a pps counter (which is the tick counter captured
at the pps edge).

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I2122ea3d636c8a430c6eb945b0c11e26e02fee43
2022-01-13 13:21:29 +01:00
Sylvain Munaut be5a53a4fe icE1usb fw: Add GPIO access functions
The 32 bit register is split in different fields to speed up
access to the 'in' field. The oe/out fields can't be split because
all writes are 32 bit wide (i.e. no support for byte enable in the
gateware)

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ic25377bb777e5d25939f0e8cfe6b7c6ef8641f6d
2022-01-13 13:21:29 +01:00
Sylvain Munaut 394748ab86 icE1usb fw: Add function to enable/disable E1 led runner
Also don't force enable the runner in the e1_platform_led_set
callback.

Due to GPIO shortage, the E1 leds control are multiplexed with
SPI so this adds a method to temporarely stop the runner so SPI
can be used.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ie671daab5ee5e0b5f58de9d4fef1f0ca7d6d02b6
2022-01-13 13:21:29 +01:00
Sylvain Munaut 5848f14563 icE1usb fw: Add more hw units to config.h along with sys clock
Those are already in the gateware, this just adds the define for
them.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I87fae20e4a987c2186d5db6747e03e7ce9789a8f
2022-01-13 13:21:29 +01:00
Sylvain Munaut 51122af10f icE1usb fw: Add missing ice1usb_proto.h to dependency list
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I63af9839f79dbb0ce40e6582c86076a6cb213b39
2022-01-13 13:21:25 +01:00
Sylvain Munaut 9c213e6ca7 icE1usb fw: Add missing usb_e1.h in the Makefile header list
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I2088700c0fc99dbb2940956dd9066ea098ef3eb6
2022-01-13 13:19:06 +01:00
Sylvain Munaut c9c22a62cd icE1usb fw: Have usb_e1 handle the E1 polling and multi port
The init already takes care of both port and also calling
e1_init, so it makes sense to have a usb_e1_poll() that
encapsulate both the actual e1 hardware poll and running
the usb stuff for both port.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Icf81efcdc5c8f13480ba2652bc6e7c1ca226ae4d
2022-01-13 13:19:06 +01:00
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 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
Sylvain Munaut 4d9aea44ef gateware/cores: Update USB core
Mostly to get firmware code improvement and fixes

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ifacacd15f989aa51c04433cfb0bdaee7f848b658
2022-01-05 22:14:47 +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
Sylvain Munaut 348f425936 gateware: Update submodules
Not much change in e1, just a typo fix that just triggered a warning.
In usb the only relevant change is a fix in the stack code that caused
GET_INTERFACE to fail for interfaces without alt-settings

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Idfe712f7a2173e5c5f9552f35136f1d732098139
2021-05-31 14:01:39 +02:00
Harald Welte 20408d3ec0 contrib/jenkins.sh: Switch from rita -> ftp.osmocom.org
We should use service-aliases and not the primary host name, as
that makes migration between machines hard.

Change-Id: Idd49f27c9b08c6cfd077f85276a3dedc4cf117ef
2021-04-22 11:23:43 +02:00