summaryrefslogtreecommitdiff
path: root/chip/g/usb-stream.h
Commit message (Collapse)AuthorAgeFilesLines
* g: re-implement usb console with usb-stream configuration.Namyoon Woo2019-09-191-0/+8
| | | | | | | | | | | | | | | | | | | | This patch introduces CONFIG_USB_CONSOLE_STREAM, which implements usb-console with usb-stream configuration, intending to remove code redundancy between the previous implementation (usb_console.c) and usb_stream.c. Flash usage decreases by 224 bytes, and RAM usage by 40 bytes. BUG=b:138447451 BRANCH=cr50 TEST=Checked cr50 USB console and cr50 UART console respectively. Key-in response and output are working well: ./util/uart_stress_tester.py /dev/ttyUSB0 -t 300 --debug Change-Id: I305038e1db83dc49bb12a8afdbfcc2a8135d50f5 Signed-off-by: Namyoon Woo <namyoon@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1741302 Reviewed-by: Mary Ruthven <mruthven@chromium.org>
* g: try batching USB stream data under heavy loadVadim Bendebury2019-06-271-1/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | USB TX data rate is much higher than UART RX, this results in USB driver streaming data received from UART in smaller than max size chunks, which in turn means that per byte overhead of shipping USB packets to the host is not as low as it could have been. This patch detects attempt to ship less than full chunk over USB stream and instead of processing data immediately posts a deferred function, which is supposed to triggers another send attempt in a few milliseconds. If there is a high traffic on the stream, the queue would have much more data after deferred interval ends. The problem with the posted deferred function is the fact that it is not guaranteed to run soon enough in case there are other deferred functions waiting. To address this issue an additional check is being introduced to make sure that the USB buffer does not overflow: if the deferred function is posted, and the buffer is half full or more, let's cancel the deferred function and process the stream right away. If the deferred function gets to execute - there is a chance that a UART and or USB interrupt comes while the deferred function is running, which is likely to mess up USB controller settings by tx_stream_handler(). To avoid these issues, interrupts are disabled before the kicker function calls the handler. Note that this optimization applies only to AP and EC console streams. BRANCH=cr50, cr50-mp BUG=b:38448364 TEST=two full chargen streams on an octopus device run indefinitely and don't seem to be interrupting even when some CLI command is ran on the Cr50 console or when an update is uploaded over USB or TPM Change-Id: Id151c494967d1eb15d2af42acf8f2282966b5147 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1672209 Reviewed-by: Namyoon Woo <namyoon@chromium.org>
* g: set up USB TX in USB endpoint interrupt handlerNamyoon Woo2019-06-271-10/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | USB TX used to be set up in a deferred function. This patch makes USB endpoint interrupt handler to setup USB TX to speed up sending data to host USB. It reduces Flash usage by 100 bytes, and RAM usage by 40 bytes. BUG=b:38448364 BRANCH=cr50, cr50-mp TEST=(1) Flashed EC FW on fleex (uut), atlas (npcx_int_spi), ampton (it83xx), bob (npcx_spi), coral (npcx_spi), and scarlet(stm32). (2) Flashed AP FW on fleex. (3) Ran firmware_Cr50DeviceState on Coral. (4) Uart Stress Tester on fleex. [ before applying this CL ] $ uart_stress_tester.sh --pty="/dev/ttyUSB2 /dev/ttyUSB1" --min_char 200000 ........................... ERROR : /dev/ttyUSB2: 1953 lost / 330330 : .5 % ERROR : /dev/ttyUSB1: 451 lost / 200655 : .2 % [ after applying this CL ] $ uart_stress_tester.sh --pty="/dev/ttyUSB2 /dev/ttyUSB1" --min_char 200000 ........................... INFO : /dev/ttyUSB2: 0 lost / 334425 : 0 % INFO : /dev/ttyUSB1: 0 lost / 200655 : 0 % Change-Id: Ic966486f034a199b601ca002f6ed76a73b2b9dd8 Signed-off-by: Namyoon Woo <namyoon@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1574661 Tested-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* Revert "g: consolidate USB console transfer codes to usb-stream"Namyoon Woo2019-06-181-10/+0
| | | | | | | | | | | | | | | | | | | | | This reverts commit 79e88d81f3e090d959669b4de6215cef96c2a3ed. Reason for revert: It slows down CR50 UART console response. The original plan was to consolidate CR50 console USB configuration into USB stream configuration, then optimize USB stream implementation. However, I am changing the plan: will commit this patch after USB stream is optimized. BUG=None BRANCH=None TEST=Downloaded the cr50 bin, and checked the cr50 console responding stable. Change-Id: I21ae8c4e043e10c4325bbf91123f2ee185faa413 Signed-off-by: Namyoon Woo <namyoon@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1662849 Commit-Queue: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* g: consolidate USB console transfer codes to usb-streamNamyoon Woo2019-06-141-0/+10
| | | | | | | | | | | | | | | | | | | usb-console.c and usb_stream.c include some amount of copied/pasted code. This patch converts USB console implementation to USB stream to reduce the redundancy. Flash usage decreases by 260 bytes. BUG=None BRANCH=None TEST=Ran uart_stress_tester.sh (http://crrev.com/c/1586581/23) on bob. This CL slightly increases CR50 console char loss rate: 5.5% -> 6.5% in average. Change-Id: Ibdc16867618d67ae33574e802c1949aa6b5cf1a6 Signed-off-by: Namyoon Woo <namyoon@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1648921 Reviewed-by: Mary Ruthven <mruthven@chromium.org>
* g: reduce a mem copy in usb upstream transferNamyoon Woo2019-06-121-6/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream data path from uart to usb for cr50/ec/ap console is as below: UART RX FIFO -> (usart) rx buffer -> usb config consumer queue -> usb tx buffer -> USB HOST This CL reduces a memory copy from consumer queue to usb tx buffer by giving the memory address of head in consumer queue in USB endpoint descriptor. This CL can set up to two endpoint descriptors since the queue is implemented as linear queue, and target data could be separated in two continuous area. This reduces RAM usage by 312 bytes, but increases Flash usage by 208 bytes. BUG=b:38448364 BRANCH=cr50 TEST=ran uart_stress_tester.sh on bob, and checked the character loss improves from 41% to 33%. Also checked flash_ec on coral, scarlet, bob, and ampton. Change-Id: I42dc07e0f4bf327f3e8bfed825f8fdc4063572b4 Signed-off-by: Namyoon Woo <namyoon@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1570148 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
* g: add rx_handled into USB_STREAM_CONFIGNamyoon Woo2019-06-061-2/+6
| | | | | | | | | | | | | | | | | | | | | The variable rx_handled tracks how many of the bytes in the HW FIFO was moved into the incoming queue. It used to be defined as local static variable for multiple USB_STREAM_CONFIGs, and could cause a problem if multiple USB downstream traffic get heavier. It should be defined for each USB_STREAM_CONFIG. This patch add rx_handled into USB_STREAM_CONFIG, which tracks how many of the bytes in the HW FIFO was moved into the incoming queue. BUG=None BRANCH=None TEST=manually ran uart_stress_tester.sh and flash_ec on Bob. Change-Id: I561a54b0594a71b557693007a181bde48155d403 Signed-off-by: Namyoon Woo <namyoon@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1644958 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* usb: Cleanup headersNicolas Boichat2017-03-161-0/+1
| | | | | | | | | | | | | | | | | | | Let's split the usb headers in 3 different parts, instead of having usb_descriptor.h pull in usb_hw.h and usb_api.h. - usb_api.h: EC functions related to usb (e.g. connect/disconnect) - usb_descriptor.h: common USB names and structures - usb_hw.h: Functions required for interactive with EC's USB HW BRANCH=none BUG=b:35587171 TEST=make buildall -j Change-Id: I37ead61e3be5e7ae464f1c9137cf02eaab0ff92e Reviewed-on: https://chromium-review.googlesource.com/454861 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Deferred: Use deferred_data instead of function pointerAnton Staaf2016-04-181-6/+6
| | | | | | | | | | | | | | | | | | | | | Previously calls to hook_call_deferred were passed the function to call, which was then looked up in the .rodata.deferred section with a linear search. This linear search can be replaced with a subtract by passing the pointer to the deferred_data object created when DECLARE_DEFERRED was invoked. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None CQ-DEPEND=CL:*255812 TEST=make buildall -j Change-Id: I951dd1541302875b102dd086154cf05591694440 Reviewed-on: https://chromium-review.googlesource.com/334315 Commit-Ready: Bill Richardson <wfrichar@chromium.org> Tested-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* g: Add USB_STREAM_CONFIG_FULL macro to usb-stream.hBill Richardson2016-04-111-12/+41
| | | | | | | | | | | | | | | | | | | It's handy to use the usb-stream interfaces to avoid a lot of typing. But not all the endpoints are traditional serial ports. This just adds a new macro that lets us specify additional parameters. BUG=chrome-os-partner:50707 BRANCH=none TEST=make buildall; test on Cr50 Verified that all the previous endpoints still work as before. There are no endpoints that use the new macro yet. Change-Id: Ia37901cbe3adc4a4650ab91db3596efa15a110de Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/338086 Reviewed-by: Mary Ruthven <mruthven@chromium.org>
* cr50: add support for creating multiple serial endpointsMary Ruthven2016-04-071-0/+192
CR50 will need three serial endpoints for the streaming AP and EC UART and exporting its own console through USB. This change adds a macro to create endpoints that can be recognized by the usb_serial driver. BUG=chrome-os-partner:50702 BRANCH=none TEST=Verify "/dev/google/Cr50*/serial/Blob" prints capital letters when lower case letters are input. Change-Id: Iddf2c957a00dc3cd5448a6a00de2cf61ef5dd84c Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/336441 Tested-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>