Commit Graph

112 Commits

Author SHA1 Message Date
Sylvain Munaut b936e3af89 icE1usb fw: Ensure alignement of the structure for the usb_data_write
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Id80468ef95bb908cf34b6eeca04c83f1285fd2f5
2024-03-07 08:51:54 +01:00
Sylvain Munaut 1f29c0fece icE1usb fw: Use proper length for struct usb_cdc_notif_serial_state
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I30d451e76ebd192f037653179b6485b2b43b6dbc
2024-03-07 08:51:54 +01:00
Sylvain Munaut ff9916bb0c gateware/cores: Update no2usb
Mostly to get firmware code fixes

Need some code adaptation in icE1usb firmware to
remove local usb_cdc_notif_serial_state struct
sine tt's included in no2usb cdc proto header now.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I13e186627077c57329e4a83da11acc01ca5dce35
2024-03-07 08:51:08 +01:00
Sylvain Munaut a53f23ad30 icE1usb fw: Workaround some apparent GCC aliasing bug ...
If the code is built either :
 * without -flto
 * with -fno-strict-aliasing
 * with that struct as 'static' (so it's not on the stack)

Then all works fine. But in the current situation (without the
patch), GCC seems to think there is some aliasing and just plain
removed the `notif.bits = 1` bit of code in that functions
(no warnings printed ...).

Putting the struct as 'static' is the least awful workaround.

I didn't bother reporting bug upstream, because I can't reproduce
on a small test case and I'm sure I'd just get yelled at and that
the compiler is right for some reason ...

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ie0a2ce337ce4a9c08c3d27acc4d922a3e5892840
2024-03-06 11:20:40 +01:00
Sylvain Munaut 71a9bcfd64 icE1usb fw: fix usb cdc notification struct attributes
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I7323c335c7cefe30446fb560b9381a3519b65f12
2024-03-06 11:16:34 +01:00
Sylvain Munaut 0036b1fa9f icE1usb fw: Add device request to read/write I2C device registers
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I55a72762d535827a51e5ea1775e9abbd116bc8a8
2022-11-09 11:14:49 +01:00
Sylvain Munaut 652c732ec4 icE1usb fw: Import I2C peripheral driver
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ib729bb5f4e94eec25c86517042cdfdcb6847ba25
2022-11-09 11:14:49 +01:00
Sylvain Munaut b722de7a2a icE1usb fw: Process read/write device requests separately
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I9a8fb3d6712c83f59e5e4cba8e0bcbd4d4f95eee
2022-11-09 11:02:51 +01:00
Sylvain Munaut 321b1c8694 icE1usb fw: Minor doc string update
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: If0b37021698b2d17b8412a1c05a9c7101b06a506
2022-11-09 11:02:51 +01:00
Sylvain Munaut 1714abcf03 icE1usb fw: Fix typo in SPDX header
Those files barely even qualify for a license anyway but for
consistency's sake ...

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I9585f7f01d2dc8393828aa264ae353e2a53a37dd
2022-11-09 11:02:51 +01:00
Sylvain Munaut 166d49d785 icE1usb fw/gpsdo: Only force HOLD_OVER when no PPS if not DISABLED
Bug introduced in da395cc922
but since we never had anyway to use manual mode before,
didn't get noticed ...

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I6e2b6cf5c7c0c9deaf429be000770316ec88b9d4
2022-11-09 11:02:51 +01:00
Harald Welte 6fc0ad3c7e fw/e1-tracer: Fix bNumInterfaces in new configuration
This fixes the following Linux kernel error message on the host:
usb 1-1: config 2 has 2 interfaces, different from the descriptor's value: 3

Change-Id: Ideb816169a1e995907901c018e7bd2f963c1a831
2022-11-02 22:06:05 +01:00
Harald Welte 6cb6e6ec15 fw/e1-tracer: Initialize IDT82V2081 from within firmware in e1d mode
Initially it was a good choice to keep the LIU driver in the host
software (easier debugging/changes).  However, we never really needed it
to do anything but initialization of the LIU.

So in order to avoid having to teach osmo-e1d or other software the
details about the LIU initialization, let's do this from the firmware
*if* the e1d compatible USB configuration is used.

Closes: OS#5733
Change-Id: Id2217ff4573c4eebd816318128f256e85fb3c3bd
2022-11-01 22:01:38 +01:00
Harald Welte f9280b0de1 fw/e1-tracer: Additional USB configuration for "osmo-e1d compatible mode"
This adds a second USB configuration to the e1-tracer firmware.  This
configuration is closer to the USB configuration of an icE1usb and hence
paves the way for using osmo-e1d with the tracer.

The main conceptual difference between the existing "legacy"
configuration and this new "e1d compatible" configuration is to have two
USB interfaces, one for each direction of the traced E1 interface.  Each
interface has its own separate two altsettings, one for the disabled
and one for the enabled state.

Unmodified osmo-e1d will not work straight away with this, as it expects
ISO OUT and ISU Feedback endpoints, which a pure rx-only tracing device
of course doesn't have.

Related: OS#5733
Change-Id: I97062b9f12317b1b9b3855409c2380108cb921ff
2022-11-01 22:01:38 +01:00
Harald Welte 326a08fe63 fw/e1-tracer: e1_start/e1_stop of individual channel
Let's split the starting and stopping between the two channels.

This is a preparation for a future e1d-compatible mode where each
channel (direction) has its own USB interface and hence must be
individually started/stopped.

Related: OS#5733
Change-Id: I7492325352222269bf0ba1346511c7dfa99c4f64
2022-11-01 21:55:51 +01:00
Harald Welte e08adb0dff fw/e1-tracer: restrict dfu programming to e1-tracer devices
Let's explicitly specify the VID/PID of the e1-tracer in the dfu-util
invocation 'make dfuprog' to avoid accidentially programming other
attached dfu capable devices.

Change-Id: I6a17f01a621cd4af6827167427fafd2f9f277755
2022-11-01 09:37:29 +01:00
Sylvain Munaut 9b3f2c4a6b icE1usb fw: Limit dfuprog to proper USB IDs
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Iaf96565b4068c2d6aa46d8bedac1fad618130a26
2022-10-04 16:16:20 +02:00
Sylvain Munaut db0b81065c icE1usb fw: Add support for building 1 channel version
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I147bb90fca3cead8db776ecfd60c23b4b8bafe2d
2022-10-04 16:16:20 +02:00
Sylvain Munaut dc1d741797 icE1usb fw: Add Notify PPS on Carrier Detect option
This is disabled by default because turns out the kernel doesn't
actually support PPS on CD for USB-CDC devices :(

And this also increase the interrupt traffic ...

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ie5d163434323a23912228003add9870fafefedf9
2022-10-04 16:16:20 +02:00
Sylvain Munaut da395cc922 icE1usb fw/gpsdo: If no PPS present for >= 3s, go to hold over mode
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ia85a8bb0e146cb117ea6e2704c6a4dedf215c75a
2022-10-04 14:58:18 +02:00
Sylvain Munaut b8fc8a6a64 icE1usb fw/gpsdo: Use PID loop instead of ad-hoc algo
The original algo is just somehting I originally came up with
on the spot and worked and I never got the time to revisit.

Now after some testing, I implemented a PID loop that seems to
present faster lock time and at least as good stability.

Parameters were not thorougly optimized just some 'hand' tuning
trying to simulate the behavior.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ie3ea7243aa4234585f1ace222632bb5580caca75
2022-10-04 14:54:36 +02:00
Sylvain Munaut ad0fc21d61 icE1usb fw/gpsdo: Use a struct for VCTXO dependent params
Not that useful for now, but prep for PID loop

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Iffea8992130eccd98a2952b08277e3d0d2568a1f
2022-10-04 14:43:56 +02:00
Sylvain Munaut cfb8b0b7a0 icE1usb fw/gpsdo: Export accumulated error
This is a pretty usefu stat as this is what actually matters

Note that structure is just extended so any call with a wLength
shorter will just get the beginning of the struct (usb stack
limits response to wLength) and thus is fully backward compatible.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I0aa919d4870ca7e1b653b82ac4f76ed26b5e3b08
2022-10-04 13:54:49 +02:00
Sylvain Munaut aae4d3059d firmware: Remove a couple of questionable debug puts()
Those were low level debug meant to be temporary and somehow ended
up committed.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ie1b802f347b0de9ea82edb61faaba6094b8f4dfa
2022-05-03 14:00:35 +02:00
Sylvain Munaut b72aba9586 icE1usb fw/gpsdo: Limit the fine tuning range
Fine tuning has a limited tuning range. If at some point we
hit the limits, we need to bit the bullet and try to 'transfer'
some of that to the coarse range as best as we can. Hopefully
we get it close enough to limit disruption.

Note that this should really never happen because although it's
limited, the tuning range should be good enough to absorb any
reasonable temperature / aging variation once we have coarse tuned.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I2d9d348f5466f581b3d6d36c98847c47e2452f98
2022-04-22 10:37:58 +02:00
Sylvain Munaut 8598d48675 icE1usb fw/gpsdo: Attempt to recover from bad tuning
If we're in hold over mode and getting a bunch of invalid
frequency measurement despite a good fix, then we most likely
ended up on a bad tuning value and we need to recover by starting
from scratch.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: If8503a3eaf695e02a0ef0a3b6536de985d247c20
2022-04-22 10:35:53 +02:00
Sylvain Munaut 103a83cbdc icE1usb fw/gpsdo: Add debug prints for coarse/fine tune entry
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ife69f9ce4c6f3eb6d40b05ce8f862ff68180357f
2022-04-21 23:28:35 +02:00
Sylvain Munaut 8014c3cd09 icE1usb fw/gpsdo: Never use invalid measurements to feed loop
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I9c7b81c6e2e600ed49ac766fa33df23747dd339e
2022-04-21 23:27:57 +02:00
Sylvain Munaut 28eb5d1b96 icE1usb fw/gpsdo: Fix typo in the condition to exit TUNE_FINE
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I6106f07f7bff1c298ac3f86164e155d4bfb1b7ac
2022-04-21 23:26:59 +02:00
Harald Welte cac342af6b icE1usb: Move GPS-DO USB control to separate USB interface
doing so significantly simplifies the development of a Linux kernel
driver, as the GPS-DO only exists once (not twice, like the per-E1-line
interface), and Linux kernel USB drivers typically are for an interface.

There is an option to write a usb_device_driver, but doing so will
exclude the per-interface drivers from still being probed in their usual
fashion.

While we introduce this new USB Interface for the GPS-DO, we also
move the related control endpoint requests from the device level to the
interface level.

Finally, some naming inconsistency between "enum
ice1usb_gpsdo_antenna_state" vs. the member name antenna_status is
resolved.

Change-Id: Icd6555a14896c38626fb147b78af44ff719f2254
2022-02-01 17:57:12 +01:00
Harald Welte fddf5990bd icE1usb: Fix ordering of USB interface numbers
The USB spec requires interface numbers to be in sequential order,
and the existing firmware fails that requirement, as is shown by
the Chapter9 test suite ("USB30CV").

With this patch applied, the USB30CV Chapter9 test suite passes.

Change-Id: I6a5434447ee20f77ce0ba9e7b1884cbd5b466439
2022-02-01 17:26:38 +01:00
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