• Jan Kundrát's avatar
    serial: max310x: Use batched reads when reasonably safe · 2b4bac48
    Jan Kundrát authored
    The hardware has a 128 byte RX FIFO buffer for each independent UART.
    Previously, the code was always reading that byte-by-byte via
    independent SPI transactions and the associated overhead. In practice,
    this led to up to eight bytes over SPI for just one byte in the UART's
    RX FIFO:
    
    - reading the global IRQ register (two bytes, one for command, the other
    for data)
    - reading one UART's ISR (again two bytes)
    - reading the byte count (two bytes yet again)
    - finally, reading one byte of the FIFO via another two-byte transaction
    
    We cannot always use a batched read. If the TTY is set to intercept
    break conditions or report framing or parity errors, then it is required
    to check the Line Status Register (LSR) for each byte which is read from
    the RX FIFO. The documentation does not show a way of doing that in a
    single SPI transaction; registers 0x00 and 0x04 are separate.
    
    In my testing, this is no silver bullet. I was feeding 2MB of random
    data over four daisy-chaned UARTs of MAX14830, and this is the
    distribution that I was getting:
    
    - R <= 1: 7437322
    - R <= 2: 162093
    - R <= 4: 4093
    - R <= 8: 4196
    - R <= 16: 645
    - R <= 32: 165
    - R <= 64: 58
    - R <= 128: 0
    
    For a reference, batching the write operations works much better:
    
    - W <= 1: 2664
    - W <= 2: 1305
    - W <= 4: 627
    - W <= 8: 371
    - W <= 16: 121
    - W <= 32: 68
    - W <= 64: 33
    - W <= 128: 63139
    
    That's probably because this HW/SW combination (Clearfog Base, Armada
    388) is probably "good enough" to react to the chip's IRQ "fast enough"
    most of the time. Still, I was getting RX overruns every now and then.
    In future, I plan to improve this by letting the RX FIFO be filled a
    little more (the chip has support for that and also for a "stale
    timeout" to prevent additional starvation).
    Signed-off-by: default avatarJan Kundrát <jan.kundrat@cesnet.cz>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    2b4bac48
max310x.c 40.4 KB