• Johan Hovold's avatar
    serial: qcom-geni: fix console corruption · cc4a0e57
    Johan Hovold authored
    The Qualcomm serial console implementation is broken and can lose
    characters when the serial port is also used for tty output.
    
    Specifically, the console code only waits for the current tx command to
    complete when all data has already been written to the fifo. When there
    are on-going longer transfers this often means that console output is
    lost when the console code inadvertently "hijacks" the current tx
    command instead of starting a new one.
    
    This can, for example, be observed during boot when console output that
    should have been interspersed with init output is truncated:
    
    	[    9.462317] qcom-snps-eusb2-hsphy fde000.phy: Registered Qcom-eUSB2 phy
    	[  OK  ] Found device KBG50ZNS256G KIOXIA Wi[    9.471743ndows.
    	[    9.539915] xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
    
    Add a new state variable to track how much data has been written to the
    fifo and use it to determine when the fifo and shift register are both
    empty. This is needed since there is currently no other known way to
    determine when the shift register is empty.
    
    This in turn allows the console code to interrupt long transfers without
    losing data.
    
    Note that the oops-in-progress case is similarly broken as it does not
    cancel any active command and also waits for the wrong status flag when
    attempting to drain the fifo (TX_FIFO_NOT_EMPTY_EN is only set when
    cancelling a command leaves data in the fifo).
    
    Fixes: c4f52879 ("tty: serial: msm_geni_serial: Add serial driver support for GENI based QUP")
    Fixes: a1fee899 ("tty: serial: qcom_geni_serial: Fix softlock")
    Fixes: 9e957a15 ("serial: qcom-geni: Don't cancel/abort if we can't get the port lock")
    Cc: stable@vger.kernel.org	# 4.17
    Reviewed-by: default avatarDouglas Anderson <dianders@chromium.org>
    Tested-by: default avatarNícolas F. R. A. Prado <nfraprado@collabora.com>
    Signed-off-by: default avatarJohan Hovold <johan+linaro@kernel.org>
    Link: https://lore.kernel.org/r/20240906131336.23625-7-johan+linaro@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    cc4a0e57
qcom_geni_serial.c 49.7 KB