Qualcomm USB4 host router
Subsystems (8)
cover Qualcomm USB4 host router
This is an early RFC, mostly looking for acks/naks regarding the bespoke power state machine and Type-C handling in qcom.c. This version of the driver can power up the hardware, have it suspend/resume, but notably not drive any tunnels (as that depends on dozens of patches to other subsystems, many with shaky dependencies on the still-forming usb4 dt-bindings [1]). Absolutely not intended for merging (unless you want to take some of the intermediate tbt patches, Mika). Speaking of dt-bindings, this posting comes with none, as it makes no sense to waste maintainer time until that GitHub discussion is settled.
Said state machine is an attempt to tame the delicate clock setup, which if we don't get perfectly right results in the machine hard- crashing. More on that in the big comment at the top of the driver.
The Qualcomm USB4 host router is an in-house design, implementing a standard NHI front-end with a lot of vendor glue. Because the USB, PCIe and DP blocks live outside the subsystem (and are wholly disjoint), a lot of elbow grease it required to have it all behave (similarly to the Apple implementation, but with more manual clock control and firmware handshakes). Native protocol controllers can only resume after the router has re-enabled the links (which collides with today's notion of nhi_resume re-enabling the tunnels), so that requires some consideration (again, not included in this posting).
USB3 tunneling requires:
* a bit in TCSR (tldr a syscon) to be toggled and the path to be enabled
* a register set in DWC3 to work around an issue with the USB3 adapter
This is a fairly low-hanging fruit, but still depends on the bindings to get the device link changes in within the USB subsystem.
PCIe tunneling requires:
* a reset in the USB4 address space to be asserted
* a number of additional settings on the RC side
* standard PCIe hotplug otherwise works as expected
The link itself works without much effort. How we set up devlinks and whether we can go forward with or dispose of the router's power state machine will shape the suspend/resume handling there though.
DP tunneling requires:
* handling a secondary mailbox within the USB4 subsystem (not included)
* setting up the display crossbar/mux correctly (any of each routers' DP adapters can be muxed to any of the available DPTXes)
* settings a couple registers in the DPTX
* driving a secondary AUX bus from within USB4SS (the AUX controller in the DPTX is blissfully unaware about the existence of USB4, so the OS has to ping-pong between them at runtime..)
* HPD management
Because of the muxing and runtime AUX switching, this requires sizeable DRM changes, including Luca Ceresoli's work on bridge hotplug.
Additionally, the hardware is constructed such that the protocol adapters need some of the native controllers' clocks and power domains to be online, hence the odd DT references.
The uC doesn't implement a CM, it instead does some housekeeping functions, but because it doesn't have a view directly into the SoC's register space, it still requires a lot of OS coordination. It does however take care of link establishment and some of the TBT-layer chores (such as sending PERST# packets to PCIe adapters). It requires loadable firmware which will be posted to linux-firmware soon.
This series runs as-is on a Glymur CRD board, minding its limited usefulness given all of the above.
I know this series is not the entire feature set and that this was promised quite some time ago now, but as I was humbled to learn, sending 80G over a wire is no easy feat. I'm looking forward to removing the remaining roadblocks and hopefully getting there in the upcoming year. Please chime into the bindings discussion on GitHub if you want to help there.
Dependencies:
* https://lore.kernel.org/linux-arm-msm/[email protected]/
* https://lore.kernel.org/linux-arm-msm/[email protected]/
* https://lore.kernel.org/linux-arm-msm/[email protected]/
* https://lore.kernel.org/linux-arm-msm/20261117-topic-pga_nousb4_glymur-v1-1-0ede74e620d0@oss.qualcomm.com/
The base commit (contrary to what b4 says, because of said dependencies) is next-20261116.
[1] https://github.com/devicetree-org/dt-schema/pull/196
---
Konrad Dybcio (13):
phy: qualcomm: qmp-combo: Add USB4 power_on/off to de/assert USB4 clamps
soc: qcom: smem: Add and export qcom_smem_get_serial_no()
clk: qcom: gcc-glymur: Don't poll the status bit of some USB4 clocks
thunderbolt: nhi: Clear ring interrupts when not using MSI-X
thunderbolt: nhi: Process ring completions in the threaded IRQ
thunderbolt: nhi: Add pre_switch_suspend hook
thunderbolt: nhi: Resume the domain if the NHI suspend op fails
thunderbolt: nhi: Resume a runtime suspended NHI for system suspend
thunderbolt: Raise TB_TIMEOUT to 500 ms
[HACK] thunderbolt: Refuse to activate DP/USB3/PCIe tunnels
thunderbolt: Introduce Qualcomm USB4 router driver
arm64: dts: qcom: glymur: Add USB4 topology
arm64: dts: qcom: glymur-crd: Enable the tertiary Type-C
Wesley Cheng (2):
phy: qualcomm: qmp-combo: Add Glymur USB4v1 PHY sequences
soc: qcom: pmic_glink_altmode: Enable TBT/USB4 negotiation
arch/arm64/boot/dts/qcom/glymur-crd.dtsi | 107 +- arch/arm64/boot/dts/qcom/glymur.dtsi | 703 ++++++- drivers/clk/qcom/gcc-glymur.c | 12 +- drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 321 ++- drivers/phy/qualcomm/phy-qcom-qmp-dp-com-v3.h | 1 + drivers/phy/qualcomm/phy-qcom-qmp-usb43-pcs-v8.h | 22 + drivers/soc/qcom/pmic_glink_altmode.c | 5 +- drivers/soc/qcom/smem.c | 22 + drivers/thunderbolt/Kconfig | 13 + drivers/thunderbolt/Makefile | 3 + drivers/thunderbolt/eeprom.c | 17 - drivers/thunderbolt/nhi.c | 168 +- drivers/thunderbolt/nhi.h | 4 +- drivers/thunderbolt/pci.c | 15 +- drivers/thunderbolt/qcom.c | 2299 ++++++++++++++++++++++ drivers/thunderbolt/qcom.h | 251 +++ drivers/thunderbolt/switch.c | 4 + drivers/thunderbolt/tb.c | 2 +- drivers/thunderbolt/tb.h | 20 + drivers/thunderbolt/tb_regs.h | 3 + drivers/thunderbolt/tunnel.c | 2 + include/linux/soc/qcom/smem.h | 1 + include/linux/thunderbolt.h | 8 +- 23 files changed, 3914 insertions(+), 89 deletions(-)
---
base-commit: 516d5c8f674bc07eb35c3b97fc21e79e41158dee
change-id: 20261124-topic-next-20261116-fsm-mvp-b936003bd2f2
Best regards,
Signature · 1 line
Konrad Dybcio <[email protected]>
RFC PATCH 1/15 phy: qualcomm: qmp-combo: Add Glymur USB4v1 PHY sequences
From: Wesley Cheng <[email protected]>
Introduce the programming sequences for Glymur, based on the V1.00 Hardware Settings Reference release for Glymur_R2.
--- drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 297 ++++++++++++++++++++++- drivers/phy/qualcomm/phy-qcom-qmp-dp-com-v3.h | 1 + drivers/phy/qualcomm/phy-qcom-qmp-usb43-pcs-v8.h | 22 ++ 3 files changed, 315 insertions(+), 5 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +292 -5
@@ -119,6 +119,7 @@ enum qphy_reg_layout {QPHY_AON_TOGGLE_ENABLE ,QPHY_DP_AON_TOGGLE_ENABLE , +QPHY_USB4_AON_TOGGLE_ENABLE ,/* Keep last to ensure regs_layout arrays are properly initialized */ QPHY_LAYOUT_SIZE };
@@ -323,8 +324,10 @@ static const unsigned int qmp_v8_n3_usb43dpphy_regs_layout[QPHY_LAYOUT_SIZE] = { [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = QPHY_V8_PCS_USB_LFPS_RXTERM_IRQ_CLEAR, [QPHY_PCS_CLAMP_ENABLE] = QPHY_V8_PCS_AON_USB3_AON_CLAMP_ENABLE, + [QPHY_PCS_USB4_CLAMP_ENABLE] = QPHY_V8_PCS_AON_USB4_AON_CLAMP_ENABLE, [QPHY_AON_TOGGLE_ENABLE] = QPHY_V8_PCS_AON_USB3_AON_TOGGLE_ENABLE, [QPHY_DP_AON_TOGGLE_ENABLE] = QPHY_V8_PCS_AON_DP_AON_TOGGLE_ENABLE, + [QPHY_USB4_AON_TOGGLE_ENABLE] = QPHY_V8_PCS_AON_USB4_AON_TOGGLE_ENABLE, [QPHY_COM_RESETSM_CNTRL] = QSERDES_V8_COM_RESETSM_CNTRL, [QPHY_COM_C_READY_STATUS] = QSERDES_V8_COM_C_READY_STATUS,
@@ -2513,6 +2516,245 @@ static const struct qmp_phy_init_tbl hawi_usb3_pcs_usb_tbl[] = {QMP_PHY_INIT_CFG (QPHY_V10_PCS_USB3_RCVR_DTCT_DLY_U3_L ,0x40 ), QMP_PHY_INIT_CFG(QPHY_V10_PCS_USB3_RCVR_DTCT_DLY_U3_H, 0x00), }; +static const struct qmp_phy_init_tbl glymur_usb4_serdes_tbl[] = { +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_SSC_STEP_SIZE1_MODE1 ,0xcc ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_SSC_STEP_SIZE2_MODE1 ,0x01 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CLK_EP_DIV_MODE1 ,0xff ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CP_CTRL_MODE1 ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_PLL_RCTRL_MODE1 ,0x16 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_PLL_CCTRL_MODE1 ,0x36 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CORECLK_DIV_MODE1 ,0x02 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_LOCK_CMP1_MODE1 ,0x24 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_LOCK_CMP2_MODE1 ,0x43 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DEC_START_MODE1 ,0x43 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DEC_START_MSB_MODE1 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DIV_FRAC_START1_MODE1 ,0xab ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DIV_FRAC_START2_MODE1 ,0x02 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DIV_FRAC_START3_MODE1 ,0x02 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_HSCLK_SEL_1 ,0x11 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_INTEGLOOP_GAIN0_MODE1 ,0xff ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_VCO_TUNE1_MODE1 ,0x0f ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_VCO_TUNE2_MODE1 ,0x03 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_BIN_VCOCAL_CMP_CODE1_MODE1 ,0x8c ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_BIN_VCOCAL_CMP_CODE2_MODE1 ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_BIN_VCOCAL_CMP_CODE1_MODE0 ,0x96 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_BIN_VCOCAL_CMP_CODE2_MODE0 ,0x1e ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_SSC_STEP_SIZE1_MODE0 ,0x9c ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_SSC_STEP_SIZE2_MODE0 ,0x01 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CLK_EP_DIV_MODE0 ,0xff ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CP_CTRL_MODE0 ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_PLL_RCTRL_MODE0 ,0x16 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_PLL_CCTRL_MODE0 ,0x36 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CORECLK_DIV_MODE0 ,0x02 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_LOCK_CMP1_MODE0 ,0x1a ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_LOCK_CMP2_MODE0 ,0x41 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DEC_START_MODE0 ,0x41 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DEC_START_MSB_MODE0 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DIV_FRAC_START1_MODE0 ,0x55 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DIV_FRAC_START2_MODE0 ,0x75 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DIV_FRAC_START3_MODE0 ,0x01 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_HSCLK_HS_SWITCH_SEL_1 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_INTEGLOOP_GAIN0_MODE0 ,0xff ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_VCO_TUNE1_MODE0 ,0x4d ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_VCO_TUNE2_MODE0 ,0x03 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_BG_TIMER ,0x0a ), + +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_SSC_EN_CENTER ,0x01 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_SSC_PER1 ,0x76 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_SSC_PER2 ,0x02 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_POST_DIV_MUX ,0x60 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CLK_ENABLE1 ,0x10 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_SYS_CLK_CTRL ,0x82 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_SYSCLK_BUF_ENABLE ,0x0a ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_PLL_IVCO ,0x7f ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_PLL_IVCO_MODE1 ,0x7f ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CMN_IETRIM ,0x0a ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CMN_IPTRIM ,0x20 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_SYSCLK_EN_SEL ,0x1a ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_LOCK_CMP_EN ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_LOCK_CMP_CFG ,0x04 ), + +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_VCO_TUNE_CTRL ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_VCO_TUNE_MAP ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CORE_CLK_EN ,0xf0 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CMN_CONFIG_1 ,0xf6 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_SVS_MODE_CLK_SEL ,0x2a ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CMN_MISC1 ,0x88 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CMN_MODE ,0x05 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_VCO_DC_LEVEL_CTRL ,0x07 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_ADDITIONAL_MISC_2 ,0x0f ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_PLL_SPARE_FOR_ECO ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DCC_CAL_1 ,0x40 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DCC_CAL_2 ,0x03 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DCC_CAL_3 ,0x60 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DCC_CAL_7 ,0x20 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_DCC_CAL_9 ,0x20 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_PSM_CAL_EN ,0x25 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_CLK_FWD_CONFIG_1 ,0x33 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_IP_CTRL_AND_DP_SEL ,0xaf ), +}; + +static const struct qmp_phy_init_tbl glymur_tb3_serdes_tbl[] = { +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_SSC_PER1 ,0x46 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_VCO_TUNE_CTRL ,0x40 ), +QMP_PHY_INIT_CFG (QSERDES_V8_USB43_COM_VCO_TUNE_MAP ,0x54 ), +}; + +static const struct qmp_phy_init_tbl glymur_usb4_pcs_tbl[] = { +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_POWER_STATE_CONFIG3 ,0xcf ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_POWER_STATE_CONFIG4 ,0x0f ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G23_LOCK_DETECT_CONFIG1 ,0x03 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G23_LOCK_DETECT_CONFIG2 ,0xc1 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G2_TXMGN_MAIN_RS ,0x51 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G3_TXMGN_MAIN_RS ,0x51 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_RX_SIGDET_LVL ,0x55 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_EQ_CONFIG1 ,0x36 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G3_EQ_CONFIG1 ,0x4b ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G3_EQ_CONFIG5 ,0x00 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G3_EQ_CONFIG6 ,0x28 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG1 ,0x83 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG2 ,0xdb ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG3 ,0x26 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG5 ,0x18 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G3_FOM_EQ_CONFIG1 ,0x83 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G3_FOM_EQ_CONFIG3 ,0x2a ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_G3_FOM_EQ_CONFIG5 ,0x18 ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_LFPS_TX_ECSTART ,0x0f ), +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_MBUS_CONFIG1 ,0xff ), +}; + +static const struct qmp_phy_init_tbl glymur_usb4_lalb_tbl[] = { +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CLKBUF_ENABLE ,0x85 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_TX_LVL_UPDATE_CTRL ,0x0d ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_PCIE5_TOP_LDO_CODE_CTRL1 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_PCIE5_TOP_LDO_CODE_CTRL2 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_PCIE5_TOP_LDO_CODE_CTRL3 ,0x80 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_PCIE5_TOP_LDO_CODE_CTRL4 ,0x8e ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_LANE_MODE_1 ,0x0c ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_LANE_MODE_2 ,0x40 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_LANE_MODE_3 ,0x41 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_LANE_MODE_4 ,0x01 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_TX0_RESTRIM_CAL_CTRL ,0x20 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_TX0_RESTRIM_POST_CAL_OFFSET ,0x10 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_TX1_RESTRIM_CAL_CTRL ,0x02 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_TX0_RESTRIM_VREF_SEL ,0x13 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_TX1_RESTRIM_VREF_SEL ,0x09 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_ANA_INTERFACE_SELECT2 ,0x1c ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_PCS_INTERFACE_SELECT1 ,0x50 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_LDO_TIMER_CTRL ,0x11 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE2_B0 ,0x1c ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE2_B1 ,0x93 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE2_B2 ,0x7c ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE2_B3 ,0x64 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE2_B4 ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE2_B5 ,0x57 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE2_B6 ,0x12 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE2_B7 ,0x1a ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE3_B0 ,0xce ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE3_B1 ,0xc4 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE3_B2 ,0xce ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE3_B3 ,0x60 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE3_B4 ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE3_B5 ,0x24 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE3_B6 ,0x5b ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_MODE_RATE3_B7 ,0x1b ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_TX_DCC_ANA_CTRL2 ,0x0c ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CMUX_DCC_POSTCAL_OFFSET ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT1_RATE2 ,0x26 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT2_RATE2 ,0x26 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT1_RATE3 ,0x26 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT2_RATE3 ,0x26 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCTRL_RATE_2_3 ,0x33 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KVCO_INIT_RATE_2_3 ,0x11 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KVCO_CAL_VCTRL_LOW_RATE_2_3 ,0x32 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KVCO_CODE_OVRD_RATE2 ,0x03 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KVCO_IDEAL_FREQ_DIFF1_RATE2 ,0x19 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KVCO_IDEAL_FREQ_DIFF2_RATE2 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KVCO_IDEAL_FREQ_DIFF1_RATE3 ,0x14 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KVCO_IDEAL_FREQ_DIFF2_RATE3 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KP_CODE_OVRD_RATE_2_3 ,0x22 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KP_CAL_UPPER_FREQ_DIFF_BND1_RATE2 ,0xff ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KP_CAL_UPPER_FREQ_DIFF_BND2_RATE2 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KP_CAL_UPPER_FREQ_DIFF_BND1_RATE3 ,0xff ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KP_CAL_UPPER_FREQ_DIFF_BND2_RATE3 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KP_CAL_LOWER_FREQ_DIFF_BND_RATE2 ,0x0a ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_KP_CAL_LOWER_FREQ_DIFF_BND_RATE3 ,0x10 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_SUMMER_CAL_SPD_MODE_RATE_0123 ,0x2f ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_IVCM_CAL_CODE_OVERRIDE_RATE2 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_IVCM_CAL_CODE_OVERRIDE_RATE3 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_IVCM_CAL_CTRL2 ,0x85 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_IVCM_CAL_CTRL3 ,0x55 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_IVCM_POSTCAL_OFFSET_RATE2 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_IVCM_POSTCAL_OFFSET_RATE3 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_SIGDET_ENABLES ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_SIGDET_CNTRL ,0xa3 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_SIGDET_LVL ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_SIGDET_DEGLITCH_CNTRL ,0x0e ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_SIGDET_CAL_CTRL1 ,0x14 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_SIGDET_CAL_CTRL2_AND_CDR_LOCK_EDGE ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_SIGDET_CAL_TRIM ,0x66 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_FREQ_LOCK_DET_DLY_RATE2 ,0xff ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_FREQ_LOCK_DET_DLY_RATE3 ,0xff ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_CP_CUR_FLL_RATE2 ,0x0a ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_CP_CUR_FLL_RATE3 ,0x0a ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_CP_CUR_PLL_RATE2 ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_CP_CUR_PLL_RATE3 ,0x02 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_FLL_DIV_RATIO_RATE_0123 ,0xe5 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_LOOP_CCODE_RATE_23 ,0x55 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_LOOP_RCODE_FAST_RATE_2_3 ,0x02 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_LOOP_RCODE_FLL_RATE_2_3 ,0x43 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_LOOP_RCODE_PLL_RATE_2_3 ,0x51 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCO_CAP_CODE_RATE_0123 ,0xff ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCO_TYPE_CONFIG ,0x17 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCO_EN_LOWFREQ ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_LOOP_FUNC_CTRL ,0xd0 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_FAST_LOCK_EN_CTRL ,0x08 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_RCVR_EN ,0x09 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_GM_CAL_EN ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_GM_CAL_RES_RATE2_3 ,0xc8 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_EOM_CTRL1 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_EOM_CTRL2 ,0x18 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_EOM_CTRL3 ,0x28 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_EQ_OFFSET_ADAPTOR_CNTRL1 ,0x44 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_OFFSET_ADAPTOR_CNTRL3 ,0x68 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_EQU_ADAPTOR_CNTRL2 ,0x0a ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_EQU_ADAPTOR_CNTRL3 ,0x0a ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_RX_EQU_ADAPTOR_CNTRL4 ,0xaa ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CTLE_POST_CAL_OFFSET_RATE_0_1_2 ,0x77 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CTLE_POST_CAL_OFFSET_RATE_3_4 ,0x77 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_VGA_CAL_CNTRL1 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_VGA_CAL_MAN_VAL_RATE2_3 ,0x2c ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_VTHRESH_CAL_MAN_VAL_RATE3 ,0x78 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_DFE_TAP3_CTRL ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_DFE_TAP3_MANVAL_KTAP ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_DFE_TAP4_CTRL ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_DFE_TAP4_MANVAL_KTAP ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_DFE_TAP5_CTRL ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_DFE_TAP5_MANVAL_KTAP ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_DFE_TAP1_DAC_ENABLE ,0x1c ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_DFE_TAP2_DAC_ENABLE ,0x1c ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_DFE_TAP345_DAC_ENABLE ,0x18 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_DFE_TAP67_DAC_ENABLE ,0x10 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_IQTUNE_CTRL ,0x58 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_IQTUNE_MAN_INDEX ,0x12 ),/* TODO: 0x11 for Mahua */ +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_IQTUNE_DIV2_CTRL_RATE0123 ,0x10 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCO_CAP_CODE_OVRD_MUXES ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_LOCK_KP_OFFSET_RATE3 ,0x20 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_FASTLOCK_CP_CUR_PLL_RATE3 ,0x02 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_DIG_BKUP_CTRL16 ,0x77 ), +}; + +static const struct qmp_phy_init_tbl glymur_tb3_pcs_tbl[] = { +QMP_PHY_INIT_CFG (QPHY_V8_USB4_PCS_POWER_STATE_CONFIG4 ,0x1f ), +}; + +static const struct qmp_phy_init_tbl glymur_tb3_lalb_tbl[] = { +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT1_RATE2 ,0x57 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT2_RATE2 ,0x27 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT1_RATE3 ,0x57 ), +QMP_PHY_INIT_CFG (QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT2_RATE3 ,0x27 ), +}; +static const struct qmp_phy_init_tbl nord_usb3_tx_tbl[] = { QMP_PHY_INIT_CFG(QSERDES_V6_TX_RES_CODE_LANE_TX, 0x00),
@@ -2729,6 +2971,12 @@ struct qmp_phy_cfg {int usb4_rx_tbl_num;const struct qmp_phy_init_tbl *usb4_pcs_tbl;int usb4_pcs_tbl_num; +const struct qmp_phy_init_tbl *usb4_pcs_tb3_ovrd_tbl; +int usb4_pcs_tb3_ovrd_num; +const struct qmp_phy_init_tbl *usb4_tx_tb3_ovrd_tbl; +int usb4_tx_tb3_ovrd_num; +/* true, if the C0 PLL needs to be reset on PHY mode changes */ +bool usb4_c0_pll_reset;/* resets to be requested */ const char *const *reset_list;
@@ -2948,6 +3196,8 @@ static const struct qmp_combo_offsets qmp_combo_usb43dp_offsets_v8 = { .dp_dp_phy = 0x2400, .txa = 0x4000, .txb = 0x5000, + .usb4_serdes = 0x3000, + .usb4_pcs = 0x3800, };static const struct qmp_phy_cfg sar2130p_usb3dpphy_cfg = {
@@ -3612,6 +3862,20 @@ static const struct qmp_phy_cfg glymur_usb3dpphy_cfg = { .configure_dp_clocks = qmp_v8_configure_dp_clocks, .configure_dp_phy = qmp_v8_configure_dp_phy, + .usb4_serdes_tbl = glymur_usb4_serdes_tbl, + .usb4_serdes_tbl_num = ARRAY_SIZE(glymur_usb4_serdes_tbl), + .usb4_serdes_tb3_ovrd_tbl = glymur_tb3_serdes_tbl, + .usb4_serdes_tb3_ovrd_num = ARRAY_SIZE(glymur_tb3_serdes_tbl), + .usb4_tx_tbl = glymur_usb4_lalb_tbl, + .usb4_tx_tbl_num = ARRAY_SIZE(glymur_usb4_lalb_tbl), + .usb4_pcs_tbl = glymur_usb4_pcs_tbl, + .usb4_pcs_tbl_num = ARRAY_SIZE(glymur_usb4_pcs_tbl), + .usb4_pcs_tb3_ovrd_tbl = glymur_tb3_pcs_tbl, + .usb4_pcs_tb3_ovrd_num = ARRAY_SIZE(glymur_tb3_pcs_tbl), + .usb4_tx_tb3_ovrd_tbl = glymur_tb3_lalb_tbl, + .usb4_tx_tb3_ovrd_num = ARRAY_SIZE(glymur_tb3_lalb_tbl), + .usb4_c0_pll_reset = true, + .regs = qmp_v8_n3_usb43dpphy_regs_layout, .reset_list = msm8996_usb3phy_reset_l, .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
@@ -4273,6 +4537,12 @@ static int qmp_combo_dp_calibrate(struct phy *phy)return ret; } +static void qmp_combo_toggle_c0_pll_reset (void __iomem *com) +{ +qphy_setbits (com,QPHY_V3_DP_COM_RESET_OVRD_CTRL2 ,0x6 ); +qphy_clrbits (com,QPHY_V3_DP_COM_RESET_OVRD_CTRL2 ,0x4 ); +} +static int qmp_combo_com_init (struct qmp_combo *qmp,bool force) {const struct qmp_phy_cfg *cfg = qmp->cfg;
@@ -4340,9 +4610,14 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force) SW_USB4PHY_RESET_MUX | SW_USB4PHY_RESET);/* override hardware control for reset of qmp phy */ -if (aon_toggle && cfg->regs[QPHY_AON_TOGGLE_ENABLE ]) { -qphy_clrbits (aon_toggle, cfg->regs[QPHY_AON_TOGGLE_ENABLE ],0x1 ); -qphy_clrbits (aon_toggle, cfg->regs[QPHY_DP_AON_TOGGLE_ENABLE ],0x1 ); +if (aon_toggle) { +if (qmp->qmpphy_mode ==QMPPHY_MODE_USB4 && + cfg->regs[QPHY_USB4_AON_TOGGLE_ENABLE ]) { +qphy_clrbits (aon_toggle, cfg->regs[QPHY_USB4_AON_TOGGLE_ENABLE ],0x1 ); + }else if (cfg->regs[QPHY_AON_TOGGLE_ENABLE ]) { +qphy_clrbits (aon_toggle, cfg->regs[QPHY_AON_TOGGLE_ENABLE ],0x1 ); +qphy_clrbits (aon_toggle, cfg->regs[QPHY_DP_AON_TOGGLE_ENABLE ],0x1 ); + } }/* Use software based port select and switch on typec orientation */
@@ -4362,6 +4637,8 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)switch (qmp->qmpphy_mode) {case QMPPHY_MODE_USB3DP :writel (USB3_MODE |DP_MODE , com +QPHY_V3_DP_COM_PHY_MODE_CTRL ); +if (cfg->usb4_c0_pll_reset) +qmp_combo_toggle_c0_pll_reset (com);/* bring both QMP USB and QMP DP PHYs PCS block out of reset */ qphy_clrbits(com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
@@ -4379,6 +4656,8 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)case QMPPHY_MODE_USB3_ONLY :writel (USB3_MODE , com +QPHY_V3_DP_COM_PHY_MODE_CTRL ); +if (cfg->usb4_c0_pll_reset) +qmp_combo_toggle_c0_pll_reset (com);/* bring QMP USB PHY PCS block out of reset */ qphy_clrbits(com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
@@ -4386,6 +4665,8 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)break ;case QMPPHY_MODE_USB4 :writel (USB4_MODE , com +QPHY_V3_DP_COM_PHY_MODE_CTRL ); +if (cfg->usb4_c0_pll_reset) +qmp_combo_toggle_c0_pll_reset (com);/* bring both QMP USB and QMP DP PHYs PCS block out of reset */ /*
@@ -4574,10 +4855,16 @@ static int qmp_combo_usb_power_on(struct phy *phy)qmp_configure (qmp->dev, pcs, pcs_tbl, pcs_tbl_num);qmp_configure (qmp->dev, qmp->pcs_misc, cfg->pcs_misc_tbl, cfg->pcs_misc_tbl_num); -if (qmp->qmpphy_mode ==QMPPHY_MODE_USB4 && qmp->usb4_phy_submode ==PHY_SUBMODE_TBT3 ) +if (qmp->qmpphy_mode ==QMPPHY_MODE_USB4 && qmp->usb4_phy_submode ==PHY_SUBMODE_TBT3 ) {qmp_configure (qmp->dev, serdes, cfg->usb4_serdes_tb3_ovrd_tbl, cfg->usb4_serdes_tb3_ovrd_num); -else if (qmp->qmpphy_mode !=QMPPHY_MODE_USB4 && pcs_usb) +qmp_configure_lane (qmp->dev, tx, cfg->usb4_tx_tb3_ovrd_tbl, + cfg->usb4_tx_tb3_ovrd_num,1 ); +qmp_configure_lane (qmp->dev, tx2, cfg->usb4_tx_tb3_ovrd_tbl, + cfg->usb4_tx_tb3_ovrd_num,2 ); +qmp_configure (qmp->dev, pcs, cfg->usb4_pcs_tb3_ovrd_tbl, + cfg->usb4_pcs_tb3_ovrd_num); + }else if (qmp->qmpphy_mode !=QMPPHY_MODE_USB4 && pcs_usb)qmp_configure (qmp->dev, pcs_usb, cfg->pcs_usb_tbl, cfg->pcs_usb_tbl_num);
drivers/phy/qualcomm/phy-qcom-qmp-dp-com-v3.h +1 -0
@@ -14,5 +14,6 @@#define QPHY_V3_DP_COM_TYPEC_CTRL 0x10#define QPHY_V3_DP_COM_TYPEC_PWRDN_CTRL 0x14#define QPHY_V3_DP_COM_RESET_OVRD_CTRL 0x1c +#define QPHY_V3_DP_COM_RESET_OVRD_CTRL2 0x20#endif
drivers/phy/qualcomm/phy-qcom-qmp-usb43-pcs-v8.h +22 -0
@@ -30,4 +30,26 @@#define QPHY_V8_USB43_PCS_EQ_CONFIG2 0x1e0#define QPHY_V8_USB43_PCS_EQ_CONFIG5 0x1ec +/* USB4 PCS registers on QMP v8 PHYs */ +#define QPHY_V8_USB4_PCS_POWER_STATE_CONFIG3 0x0ac +#define QPHY_V8_USB4_PCS_POWER_STATE_CONFIG4 0x0b0 +#define QPHY_V8_USB4_PCS_G23_LOCK_DETECT_CONFIG1 0x0e4 +#define QPHY_V8_USB4_PCS_G23_LOCK_DETECT_CONFIG2 0x0e8 +#define QPHY_V8_USB4_PCS_G2_TXMGN_MAIN_RS 0x118 +#define QPHY_V8_USB4_PCS_G3_TXMGN_MAIN_RS 0x144 +#define QPHY_V8_USB4_PCS_RX_SIGDET_LVL 0x29c +#define QPHY_V8_USB4_PCS_EQ_CONFIG1 0x2e0 +#define QPHY_V8_USB4_PCS_G3_EQ_CONFIG1 0x300 +#define QPHY_V8_USB4_PCS_G3_EQ_CONFIG5 0x310 +#define QPHY_V8_USB4_PCS_G3_EQ_CONFIG6 0x314 +#define QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG1 0x340 +#define QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG2 0x344 +#define QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG3 0x348 +#define QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG5 0x350 +#define QPHY_V8_USB4_PCS_G3_FOM_EQ_CONFIG1 0x35c +#define QPHY_V8_USB4_PCS_G3_FOM_EQ_CONFIG3 0x364 +#define QPHY_V8_USB4_PCS_G3_FOM_EQ_CONFIG5 0x36c +#define QPHY_V8_USB4_PCS_LFPS_TX_ECSTART 0x3a0 +#define QPHY_V8_USB4_PCS_MBUS_CONFIG1 0x3a8 +#endif
Signature · 1 line
2.55.0
RFC PATCH 2/15 phy: qualcomm: qmp-combo: Add USB4 power_on/off to de/assert USB4 clamps
In reply to Konrad DybcioThe USB4 part of the PHY comes with its own clamps, which need to be asserted during suspend. Use phy_power_on/off to let the router driver do that.
--- drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +24 -0
@@ -5085,6 +5085,28 @@ static int qmp_combo_usb4_exit(struct phy *phy)return 0 ; } +static int qmp_combo_usb4_power_on (struct phy *phy) +{ +struct qmp_combo *qmp =phy_get_drvdata (phy); + +guard (mutex)(&qmp->phy_mutex); + +qphy_setbits (qmp->pcs_aon, qmp->cfg->regs[QPHY_PCS_USB4_CLAMP_ENABLE ],CLAMP_EN ); + +return 0 ; +} + +static int qmp_combo_usb4_power_off (struct phy *phy) +{ +struct qmp_combo *qmp =phy_get_drvdata (phy); + +guard (mutex)(&qmp->phy_mutex); + +qphy_clrbits (qmp->pcs_aon, qmp->cfg->regs[QPHY_PCS_USB4_CLAMP_ENABLE ],CLAMP_EN ); + +return 0 ; +} +static int qmp_combo_usb4_set_mode (struct phy *phy,enum phy_mode mode,int submode) {struct qmp_combo *qmp =phy_get_drvdata (phy);
@@ -5110,6 +5132,8 @@ static const struct phy_ops qmp_combo_usb_phy_ops = {static const struct phy_ops qmp_combo_usb4_phy_ops = { .init = qmp_combo_usb4_init, .exit = qmp_combo_usb4_exit, + .power_on = qmp_combo_usb4_power_on, + .power_off = qmp_combo_usb4_power_off, .set_mode = qmp_combo_usb4_set_mode, .owner =THIS_MODULE , };
Signature · 1 line
2.55.0
RFC PATCH 3/15 soc: qcom: smem: Add and export qcom_smem_get_serial_no()
In reply to Konrad DybcioThe USB4 router expects that the OS programs a silicon-unique value as part of its initialization flow. The most obvious choice for that is the part's serial number.
Export a function to get the SN retrieved from SMEM.
--- drivers/soc/qcom/smem.c | 22 ++++++++++++++++++++++ include/linux/soc/qcom/smem.h | 1 + 2 files changed, 23 insertions(+)
drivers/soc/qcom/smem.c +22 -0
@@ -912,6 +912,28 @@ int qcom_smem_get_feature_code(u32 *code) }EXPORT_SYMBOL_GPL (qcom_smem_get_feature_code); +/** +* qcom_smem_get_serial_no() - return the unique serial number of the SoC +* @id: Pointer to where to store the serial number upon success. +* +* Look up serial number from HW/SW build ID and return it. +* +* Return: 0 on success, negative errno on failure. +*/ +int qcom_smem_get_serial_no (u32 *id) +{ +struct socinfo *info; + + info =qcom_smem_get (QCOM_SMEM_HOST_ANY ,SMEM_HW_SW_BUILD_ID ,NULL ); +if (IS_ERR (info)) +return PTR_ERR (info); + + *id =__le32_to_cpu (info->serial_num); + +return 0 ; +} +EXPORT_SYMBOL_GPL (qcom_smem_get_serial_no); +static int qcom_smem_get_sbl_version (struct qcom_smem *smem) {struct smem_header *header;
include/linux/soc/qcom/smem.h +1 -0
@@ -14,6 +14,7 @@ phys_addr_t qcom_smem_virt_to_phys(void *p);int qcom_smem_get_soc_id (u32 *id);int qcom_smem_get_feature_code (u32 *code); +int qcom_smem_get_serial_no (u32 *id);int qcom_smem_bust_hwspin_lock_by_host (unsigned int host);
Signature · 1 line
2.55.0
RFC PATCH 4/15 soc: qcom: pmic_glink_altmode: Enable TBT/USB4 negotiation
In reply to Konrad DybcioFrom: Wesley Cheng <[email protected]>
Now that USB4 is supported, stop identifying as an installer image and report the default OS type instead. Newer versions of the Glymur SoCCP firmware require this argument before they enable USB4 tunneling.
--- drivers/soc/qcom/pmic_glink_altmode.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/soc/qcom/pmic_glink_altmode.c +2 -3
@@ -571,10 +571,9 @@ static void pmic_glink_altmode_enable_worker(struct work_struct *work)struct pmic_glink_altmode *altmode =work_to_altmode (work);int ret; -/* Set OS to installer for now to restrict USB4/TBT negotiation */ ret =pmic_glink_altmode_request (altmode,ALTMODE_PAN_EN , -FIELD_PREP (PAN_EN_VERSION ,1 ) | -FIELD_PREP (PAN_EN_OS_TYPE ,PAN_EN_OS_INSTALLER )); +FIELD_PREP (PAN_EN_VERSION ,0 ) | +FIELD_PREP (PAN_EN_OS_TYPE ,PAN_EN_OS_DEFAULT ));if (ret)dev_err (altmode->dev,"failed to request altmode notifications: %d\n" , ret); }
Signature · 1 line
2.55.0
RFC PATCH 5/15 clk: qcom: gcc-glymur: Don't poll the status bit of some USB4 clocks
In reply to Konrad DybcioThese clocks are PHY-sourced and their halt bits seem not to update reliably. Ignore it to prevent spurious warnings.
--- drivers/clk/qcom/gcc-glymur.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/clk/qcom/gcc-glymur.c +6 -6
@@ -6833,7 +6833,7 @@ static struct clk_branch gcc_usb4_0_phy_pcie_pipe_clk = {static struct clk_branch gcc_usb4_0_phy_rx0_clk = { .halt_reg =0x2b0c4 , - .halt_check =BRANCH_HALT , + .halt_check =BRANCH_HALT_SKIP , .clkr = { .enable_reg =0x2b0c4 , .enable_mask =BIT (0 ),
@@ -6851,7 +6851,7 @@ static struct clk_branch gcc_usb4_0_phy_rx0_clk = {static struct clk_branch gcc_usb4_0_phy_rx1_clk = { .halt_reg =0x2b0d8 , - .halt_check =BRANCH_HALT , + .halt_check =BRANCH_HALT_SKIP , .clkr = { .enable_reg =0x2b0d8 , .enable_mask =BIT (0 ),
@@ -7068,7 +7068,7 @@ static struct clk_branch gcc_usb4_1_phy_pcie_pipe_clk = {static struct clk_branch gcc_usb4_1_phy_rx0_clk = { .halt_reg =0x2d0e8 , - .halt_check =BRANCH_HALT , + .halt_check =BRANCH_HALT_SKIP , .clkr = { .enable_reg =0x2d0e8 , .enable_mask =BIT (0 ),
@@ -7086,7 +7086,7 @@ static struct clk_branch gcc_usb4_1_phy_rx0_clk = {static struct clk_branch gcc_usb4_1_phy_rx1_clk = { .halt_reg =0x2d0fc , - .halt_check =BRANCH_HALT , + .halt_check =BRANCH_HALT_SKIP , .clkr = { .enable_reg =0x2d0fc , .enable_mask =BIT (0 ),
@@ -7303,7 +7303,7 @@ static struct clk_branch gcc_usb4_2_phy_pcie_pipe_clk = {static struct clk_branch gcc_usb4_2_phy_rx0_clk = { .halt_reg =0xe00c8 , - .halt_check =BRANCH_HALT , + .halt_check =BRANCH_HALT_SKIP , .clkr = { .enable_reg =0xe00c8 , .enable_mask =BIT (0 ),
@@ -7321,7 +7321,7 @@ static struct clk_branch gcc_usb4_2_phy_rx0_clk = {static struct clk_branch gcc_usb4_2_phy_rx1_clk = { .halt_reg =0xe00dc , - .halt_check =BRANCH_HALT , + .halt_check =BRANCH_HALT_SKIP , .clkr = { .enable_reg =0xe00dc , .enable_mask =BIT (0 ),
Signature · 1 line
2.55.0
RFC PATCH 6/15 thunderbolt: nhi: Clear ring interrupts when not using MSI-X
In reply to Konrad DybcioCommit 468c49f44759 ("thunderbolt: Disable interrupt auto clear for rings") made the hardware stop clearing the ring interrupt status on read for all routers except Intel ones, and added an explicit write to REG_RING_INT_CLEAR to the MSI-X handler. The single-interrupt handler was not updated though, so for such routers the status bits are never cleared and the interrupt keeps firing.
Write back the bits that were found set in each notify register to REG_RING_INT_CLEAR, before handling the rings that they belong to.
--- drivers/thunderbolt/nhi.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/thunderbolt/nhi.c +9 -2
@@ -1036,13 +1036,20 @@ void nhi_interrupt_work(struct work_struct *work)/* * Starting at REG_RING_NOTIFY_BASE there are three status bitfields * (TX, RX, RX overflow). We iterate over the bits and read a new -* dwords as required. The registers are cleared on read. +* dwords as required. The registers are cleared on read, unless +* auto-clear is disabled, in which case the bits that were set have +* to be written back to REG_RING_INT_CLEAR. */ for (bit =0 ; bit <3 * nhi->hop_count; bit++) { -if (bit %32 ==0 ) +if (bit %32 ==0 ) { value =ioread32 (nhi->iobase +REG_RING_NOTIFY_BASE +4 * (bit /32 )); +if (!(nhi->quirks &QUIRK_AUTO_CLEAR_INT )) +iowrite32 (value, nhi->iobase + +REG_RING_INT_CLEAR + +4 * (bit /32 )); + }if (++hop == nhi->hop_count) { hop =0 ; type++;
Signature · 1 line
2.55.0
Mika Westerberg
AppliedRe: [PATCH RFC DNM 06/15] thunderbolt: nhi: Clear ring interrupts when not using MSI-X
Hi,
Quoted 7 lines · Konrad Dybcio
Commit
468c49f44759("thunderbolt: Disable interrupt auto clear for rings") made the hardware stop clearing the ring interrupt status on read for all routers except Intel ones, and added an explicit write toREG_RING_INT_CLEARto the MSI-X handler. The single-interrupt handler was not updated though, so for such routers the status bits are never cleared and the interrupt keeps firing.
Quoted 5 lines
Write back the bits that were found set in each notify register to
REG_RING_INT_CLEAR, before handling the rings that they belong to.Fixes 468c49f44759 ("thunderbolt: Disable interrupt auto clear for rings")Signed-off-by Konrad Dybcio <[email protected]>
Applied to thunderbolt.git/next.
RFC PATCH 7/15 thunderbolt: nhi: Process ring completions in the threaded IRQ
In reply to Konrad DybcioThe Qualcomm USB4 router uses a shared IRQ for all NHI rings. Scheduling a work item from its threaded handler adds another delay before completed RX frames are consumed and replacement buffers are posted.
Process completed descriptors directly from the threaded IRQ instead. Harvest all completed frames while holding the NHI and ring locks, replenish RX rings immediately, then invoke frame callbacks after dropping the locks. Preserve the existing polling-ring path, which must continue to mask the interrupt and start polling instead.
This removes the workqueue round trip from the common IRQ path without calling ring consumers under NHI locking. Since the callbacks no longer run only from ring->work, have tb_ring_stop() and tb_ring_free() synchronize with the ring interrupt, so they keep returning only after all callbacks of the ring have finished.
Switch the single MSI fallback of the PCI glue over to the same threaded handler, which allows dropping nhi_interrupt_work() and the work item that backed it.
Based on related work by Wesley Cheng.
--- drivers/thunderbolt/nhi.c | 133 +++++++++++++++++++++++++++++++++++--------- drivers/thunderbolt/nhi.h | 2 +- drivers/thunderbolt/pci.c | 15 ++--- include/linux/thunderbolt.h | 8 +-- 4 files changed, 115 insertions(+), 43 deletions(-)
drivers/thunderbolt/nhi.c +106 -27
@@ -310,6 +310,41 @@ static void ring_write_descriptors(struct tb_ring *ring, bool notify)__ring_notify (ring); } +/* +* ring_harvest() - collect completed frames +* @ring: Ring to collect the frames from +* @done: List to move the completed frames to +* +* Moves all completed frames from the ring buffer to @done and writes new +* frames to the ring buffer. +* +* ring->lock is held. +*/ +static void ring_harvest (struct tb_ring *ring,struct list_head *done) +{ +struct ring_frame *frame; + +lockdep_assert_held (&ring->lock); + +while (!ring_empty (ring)) { +if (!(ring->descriptors[ring->tail].flags + &RING_DESC_COMPLETED )) +break ; + frame =list_first_entry (&ring->in_flight,typeof (*frame), + list); +list_move_tail (&frame->list, done); +if (!ring->is_tx) { + frame->size = ring->descriptors[ring->tail].length; + frame->eof = ring->descriptors[ring->tail].eof; + frame->sof = ring->descriptors[ring->tail].sof; + frame->flags = ring->descriptors[ring->tail].flags; + } + frame->ring = ring; + ring->tail = (ring->tail +1 ) % ring->size; + } +ring_write_descriptors (ring, true); +} +/* * ring_work() - progress completed frames *
@@ -337,22 +372,7 @@ static void ring_work(struct work_struct *work) goto invoke_callback; } -while (!ring_empty (ring)) { -if (!(ring->descriptors[ring->tail].flags - &RING_DESC_COMPLETED )) -break ; - frame =list_first_entry (&ring->in_flight,typeof (*frame), - list); -list_move_tail (&frame->list, &done); -if (!ring->is_tx) { - frame->size = ring->descriptors[ring->tail].length; - frame->eof = ring->descriptors[ring->tail].eof; - frame->sof = ring->descriptors[ring->tail].sof; - frame->flags = ring->descriptors[ring->tail].flags; - } - ring->tail = (ring->tail +1 ) % ring->size; - } -ring_write_descriptors (ring, true); +ring_harvest (ring, &done); invoke_callback:/* allow callbacks to schedule new work */
@@ -371,6 +391,35 @@ static void ring_work(struct work_struct *work)wake_up (&ring->wait); } +/* +* ring_process_completions() - invoke the callbacks of completed frames +* @done: Frames collected by ring_harvest(), possibly from several rings +* +* The frames of each ring are contiguous in @done. Like ring_work(), wake +* up the waiters of a ring once the callbacks of all its frames have run. +*/ +static void ring_process_completions (struct list_head *done) +{ +struct ring_frame *frame; +struct tb_ring *ring; + +while (!list_empty (done)) { + frame =list_first_entry (done,typeof (*frame), list); + ring = frame->ring; +/* +* The callback may reenqueue or delete frame. +* Do not hold on to it. +*/ +list_del_init (&frame->list); +if (frame->callback) + frame->callback (ring, frame, false); + +if (list_empty (done) || +list_first_entry (done,typeof (*frame), list)->ring != ring) +wake_up (&ring->wait); + } +} +int __tb_ring_enqueue (struct tb_ring *ring,struct ring_frame *frame,bool more) {unsigned long flags;
@@ -819,6 +868,19 @@ static bool tb_ring_empty(struct tb_ring *ring)return list_empty (&ring->in_flight); } +/* +* ring_sync_irq() - wait for the interrupt handler of a ring +* +* nhi_msi_thread() invokes the callbacks of the frames it has harvested +* after dropping the locks, so make sure it has finished with any frames +* of a ring that has been stopped or dissociated from the NHI. +*/ +static void ring_sync_irq (struct tb_ring *ring) +{ +if (ring->irq >0 ) +synchronize_irq (ring->irq); +} +/** * tb_ring_flush() - Waits for a ring to be empty * @ring: Ring to wait
@@ -881,6 +943,8 @@ void tb_ring_stop(struct tb_ring *ring)spin_unlock (&ring->lock);spin_unlock_irq (&ring->nhi->lock); +ring_sync_irq (ring); +/* * schedule ring->work to invoke callbacks on all remaining frames. */
@@ -906,7 +970,7 @@ void tb_ring_free(struct tb_ring *ring)spin_lock_irq (&ring->nhi->lock);/* * Dissociate the ring from the NHI. This also ensures that -* nhi_interrupt_work cannot reschedule ring->work. +* nhi_msi_thread() cannot harvest its frames anymore. */ if (ring->is_tx) ring->nhi->tx_rings[ring->hop] =NULL ;
@@ -919,6 +983,8 @@ void tb_ring_free(struct tb_ring *ring) }spin_unlock_irq (&ring->nhi->lock); +ring_sync_irq (ring); +if (nhi->ops->release_ring_irq) nhi->ops->release_ring_irq (ring);
@@ -935,8 +1001,8 @@ void tb_ring_free(struct tb_ring *ring)/* * ring->work can no longer be scheduled (it is scheduled only -* by nhi_interrupt_work, ring_stop and ring_msix). Wait for it -* to finish before freeing the ring. +* by ring_stop and ring_msix). Wait for it to finish before +* freeing the ring. */ flush_work (&ring->work);lockdep_unregister_key (&ring->lock_key);
@@ -1022,16 +1088,18 @@ enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi)return (enum nhi_fw_mode )val; } -void nhi_interrupt_work (struct work_struct *work) +irqreturn_t nhi_msi_thread (int irq,void *data) { -struct tb_nhi *nhi =container_of (work,typeof (*nhi), interrupt_work); +struct tb_nhi *nhi = data; +LIST_HEAD (completed_frames); +unsigned long flags;int value =0 ;/* Suppress uninitialized usage warning. */ int bit;int hop =-1 ;int type =0 ;/* current interrupt type 0: TX, 1: RX, 2: RX overflow */ struct tb_ring *ring; -spin_lock_irq (&nhi->lock); +spin_lock_irqsave (&nhi->lock, flags);/* * Starting at REG_RING_NOTIFY_BASE there are three status bitfields
@@ -1073,17 +1141,28 @@ void nhi_interrupt_work(struct work_struct *work) }spin_lock (&ring->lock); -__ring_interrupt (ring); +/* +* Harvest the completions right away instead of deferring +* to ring->work, so that the RX buffers are reposted without +* another scheduling delay during a burst. +*/ +if (ring->start_poll) +__ring_interrupt (ring); +else if (ring->running) +ring_harvest (ring, &completed_frames);spin_unlock (&ring->lock); } -spin_unlock_irq (&nhi->lock); +spin_unlock_irqrestore (&nhi->lock, flags); + +if (!list_empty (&completed_frames)) +ring_process_completions (&completed_frames); + +return IRQ_HANDLED ; }irqreturn_t nhi_msi (int irq,void *data) { -struct tb_nhi *nhi = data; -schedule_work (&nhi->interrupt_work); -return IRQ_HANDLED ; +return IRQ_WAKE_THREAD ; }static int __nhi_suspend_noirq (struct device *dev,bool wakeup)
drivers/thunderbolt/nhi.h +1 -1
@@ -31,8 +31,8 @@ int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data);enum nhi_fw_mode nhi_mailbox_mode (struct tb_nhi *nhi);void nhi_enable_int_throttling (struct tb_nhi *nhi);void nhi_disable_interrupts (struct tb_nhi *nhi); -void nhi_interrupt_work (struct work_struct *work);irqreturn_t nhi_msi (int irq,void *data); +irqreturn_t nhi_msi_thread (int irq,void *data);irqreturn_t ring_msix (int irq,void *data);int nhi_probe (struct tb_nhi *nhi);void nhi_shutdown (struct tb_nhi *nhi);
drivers/thunderbolt/pci.c +4 -11
@@ -206,14 +206,13 @@ static int nhi_pci_init_msi(struct tb_nhi *nhi)if (nvec <0 )return nvec; -INIT_WORK (&nhi->interrupt_work, nhi_interrupt_work); - irq =pci_irq_vector (pdev,0 );if (irq <0 )return irq; - res =devm_request_irq (&pdev->dev, irq, nhi_msi, -IRQF_NO_SUSPEND ,"thunderbolt" , nhi); + res =devm_request_threaded_irq (&pdev->dev, irq, nhi_msi, + nhi_msi_thread, +IRQF_NO_SUSPEND ,"thunderbolt" , nhi);if (res)return res; }
@@ -311,14 +310,8 @@ static void nhi_pci_release_irq(struct tb_nhi *nhi)struct tb_nhi_pci *nhi_pci =nhi_to_pci (nhi);struct pci_dev *pdev =to_pci_dev (nhi->dev); -/* -* We have to release the irq before calling flush_work. Otherwise an -* already executing IRQ handler could call schedule_work again. -*/ -if (!pdev->msix_enabled) { +if (!pdev->msix_enabled)devm_free_irq (nhi->dev, pdev->irq, nhi); -flush_work (&nhi->interrupt_work); - }ida_destroy (&nhi_pci->msix_ida); }
include/linux/thunderbolt.h +4 -4
@@ -501,7 +501,8 @@ void tb_service_properties_changed(struct tb_service *svc);/** * struct tb_nhi - thunderbolt native host interface * @lock: Must be held during ring creation/destruction. Is acquired by -* interrupt_work when dispatching interrupts to individual rings. +* the interrupt thread when dispatching interrupts to individual +* rings. * @dev: Device associated with this NHI instance * @ops: NHI specific optional ops * @iobase: MMIO space of the NHI
@@ -511,8 +512,6 @@ void tb_service_properties_changed(struct tb_service *svc);* @going_away: The host controller device is about to disappear so when * this flag is set, avoid touching the hardware anymore. * @iommu_dma_protection: An IOMMU will isolate external-facing ports. -* @interrupt_work: Work scheduled to handle ring interrupt when no -* MSI-X is used. * @hop_count: Number of rings (end point hops) supported by NHI. * @quirks: NHI specific quirks if any * @domain_released: Completed when domain has been fully released
@@ -532,7 +531,6 @@ struct tb_nhi {u32 *interrupt_mask;bool going_away;bool iommu_dma_protection; -struct work_struct interrupt_work;u32 hop_count;unsigned long quirks;struct completion domain_released;
@@ -639,11 +637,13 @@ enum ring_desc_flags {* @flags: Flags for the frame (see &enum ring_desc_flags) * @eof: End of frame protocol defined field * @sof: Start of frame protocol defined field +* @ring: Ring the frame was completed on */ struct ring_frame {dma_addr_t buffer_phy;ring_cb callback;struct list_head list; +struct tb_ring *ring;u32 size:12 ;u32 flags:12 ;u32 eof:4 ;
Signature · 1 line
2.55.0
Re: [PATCH RFC DNM 07/15] thunderbolt: nhi: Process ring completions in the threaded IRQ
Hi,
Quoted 17 lines · Konrad Dybcio
The Qualcomm USB4 router uses a shared IRQ for all NHI rings. Scheduling a work item from its threaded handler adds another delay before completed RX frames are consumed and replacement buffers are posted.
Process completed descriptors directly from the threaded IRQ instead. Harvest all completed frames while holding the NHI and ring locks, replenish RX rings immediately, then invoke frame callbacks after dropping the locks. Preserve the existing polling-ring path, which must continue to mask the interrupt and start polling instead.
This removes the workqueue round trip from the common IRQ path without calling ring consumers under NHI locking. Since the callbacks no longer run only from
ring->work, havetb_ring_stop()andtb_ring_free()synchronize with the ring interrupt, so they keep returning only after all callbacks of the ring have finished.
Quoted 3 lines
Switch the single MSI fallback of the PCI glue over to the same threaded handler, which allows dropping
nhi_interrupt_work()and the work item that backed it.
The MSI code can go. All the hardware supports MSI-X so that code path is really not needed. I think the MediaTek folks are doing that already though.
Quoted 15 lines
Based on related work by Wesley Cheng.
Signed-off-by Konrad Dybcio <[email protected]>--- drivers/thunderbolt/nhi.c | 133 +++++++++++++++++++++++++++++++++++--------- drivers/thunderbolt/nhi.h | 2 +- drivers/thunderbolt/pci.c | 15 ++--- include/linux/thunderbolt.h | 8 +-- 4 files changed, 115 insertions(+), 43 deletions(-)drivers/thunderbolt/nhi.c +0
-0
drivers/thunderbolt/nhi.c static void ring_write_descriptors(struct tb_ring *ring, bool notify) · line 313
Quoted 4 lines
drivers/thunderbolt/nhi.c +1
-0@@ -310,6 +310,41 @@ static void ring_write_descriptors(struct tb_ring *ring, bool notify)__ring_notify (ring); } +/*
Use /** for kernel doc
drivers/thunderbolt/nhi.c static void ring_write_descriptors(struct tb_ring *ring, bool notify) · line 321
Quoted 8 lines
drivers/thunderbolt/nhi.c +8
-0+* ring_harvest() - collect completed frames +* @ring: Ring to collect the frames from +* @done: List to move the completed frames to +* +* Moves all completed frames from the ring buffer to @done and writes new +* frames to the ring buffer. +* +* ring->lock is held.
You can drop this comment if you have the lockdep_assert below.
Quoted 14 lines
drivers/thunderbolt/nhi.c +14
-0+*/ +static void ring_harvest (struct tb_ring *ring,struct list_head *done) +{ +struct ring_frame *frame; + +lockdep_assert_held (&ring->lock); + +while (!ring_empty (ring)) { +if (!(ring->descriptors[ring->tail].flags + &RING_DESC_COMPLETED )) +break ; + frame =list_first_entry (&ring->in_flight,typeof (*frame), + list); +list_move_tail (&frame->list, done);
drivers/thunderbolt/nhi.c static void ring_write_descriptors(struct tb_ring *ring, bool notify) · line 345
Quoted 10 lines
drivers/thunderbolt/nhi.c +10
-0+if (!ring->is_tx) { + frame->size = ring->descriptors[ring->tail].length; + frame->eof = ring->descriptors[ring->tail].eof; + frame->sof = ring->descriptors[ring->tail].sof; + frame->flags = ring->descriptors[ring->tail].flags; + } + frame->ring = ring; + ring->tail = (ring->tail +1 ) % ring->size; + } +ring_write_descriptors (ring, true);
Please check if tb_ring_poll() can be made to use this as well.
Quoted 30 lines
drivers/thunderbolt/nhi.c +3
-16+} +/* * ring_work() - progress completed frames * @@ -337,22 +372,7 @@ static void ring_work(struct work_struct *work) goto invoke_callback; } -while (!ring_empty (ring)) { -if (!(ring->descriptors[ring->tail].flags - &RING_DESC_COMPLETED )) -break ; - frame =list_first_entry (&ring->in_flight,typeof (*frame), - list); -list_move_tail (&frame->list, &done); -if (!ring->is_tx) { - frame->size = ring->descriptors[ring->tail].length; - frame->eof = ring->descriptors[ring->tail].eof; - frame->sof = ring->descriptors[ring->tail].sof; - frame->flags = ring->descriptors[ring->tail].flags; - } - ring->tail = (ring->tail +1 ) % ring->size; - } -ring_write_descriptors (ring, true); +ring_harvest (ring, &done); invoke_callback:/* allow callbacks to schedule new work */
drivers/thunderbolt/nhi.c static void ring_work(struct work_struct *work) · line 394
Quoted 4 lines
drivers/thunderbolt/nhi.c +1
-0@@ -371,6 +391,35 @@ static void ring_work(struct work_struct *work)wake_up (&ring->wait); } +/*
Here too /**
drivers/thunderbolt/nhi.c static void ring_work(struct work_struct *work) · line 406
Quoted 12 lines
drivers/thunderbolt/nhi.c +12
-0+* ring_process_completions() - invoke the callbacks of completed frames +* @done: Frames collected by ring_harvest(), possibly from several rings +* +* The frames of each ring are contiguous in @done. Like ring_work(), wake +* up the waiters of a ring once the callbacks of all its frames have run. +*/ +static void ring_process_completions (struct list_head *done) +{ +struct ring_frame *frame; +struct tb_ring *ring; + +while (!list_empty (done)) {
struct ring_frame *frame; struct tb_ring *ring;
drivers/thunderbolt/nhi.c static void ring_work(struct work_struct *work) · line 410
Quoted 4 lines
drivers/thunderbolt/nhi.c +4
-0+ frame =list_first_entry (done,typeof (*frame), list); + ring = frame->ring; +/* +* The callback may reenqueue or delete frame.
re-enqueue?
drivers/thunderbolt/nhi.c static void ring_work(struct work_struct *work) · line 416
Quoted 6 lines
drivers/thunderbolt/nhi.c +6
-0+* Do not hold on to it. +*/ +list_del_init (&frame->list); +if (frame->callback) + frame->callback (ring, frame, false); +
This could use a comment. I think we can do the wake_up() outside of the loop except when ring is changed. Whichever looks more readable.
Quoted 10 lines
drivers/thunderbolt/nhi.c +6
-0+if (list_empty (done) || +list_first_entry (done,typeof (*frame), list)->ring != ring) +wake_up (&ring->wait); + } +} +int __tb_ring_enqueue (struct tb_ring *ring,struct ring_frame *frame,bool more) {unsigned long flags;
drivers/thunderbolt/nhi.c static bool tb_ring_empty(struct tb_ring *ring) · line 871
Quoted 4 lines
drivers/thunderbolt/nhi.c +1
-0@@ -819,6 +868,19 @@ static bool tb_ring_empty(struct tb_ring *ring)return list_empty (&ring->in_flight); } +/*
Same here /**
ditto everywhere.
Quoted 209 lines
drivers/thunderbolt/nhi.c +40
-11+* ring_sync_irq() - wait for the interrupt handler of a ring +* +* nhi_msi_thread() invokes the callbacks of the frames it has harvested +* after dropping the locks, so make sure it has finished with any frames +* of a ring that has been stopped or dissociated from the NHI. +*/ +static void ring_sync_irq (struct tb_ring *ring) +{ +if (ring->irq >0 ) +synchronize_irq (ring->irq); +} +/** * tb_ring_flush() - Waits for a ring to be empty * @ring: Ring to wait @@ -881,6 +943,8 @@ void tb_ring_stop(struct tb_ring *ring)spin_unlock (&ring->lock);spin_unlock_irq (&ring->nhi->lock); +ring_sync_irq (ring); +/* * schedule ring->work to invoke callbacks on all remaining frames. */ @@ -906,7 +970,7 @@ void tb_ring_free(struct tb_ring *ring)spin_lock_irq (&ring->nhi->lock);/* * Dissociate the ring from the NHI. This also ensures that -* nhi_interrupt_work cannot reschedule ring->work. +* nhi_msi_thread() cannot harvest its frames anymore. */ if (ring->is_tx) ring->nhi->tx_rings[ring->hop] =NULL ;@@ -919,6 +983,8 @@ void tb_ring_free(struct tb_ring *ring) }spin_unlock_irq (&ring->nhi->lock); +ring_sync_irq (ring); +if (nhi->ops->release_ring_irq) nhi->ops->release_ring_irq (ring);@@ -935,8 +1001,8 @@ void tb_ring_free(struct tb_ring *ring)/* * ring->work can no longer be scheduled (it is scheduled only -* by nhi_interrupt_work, ring_stop and ring_msix). Wait for it -* to finish before freeing the ring. +* by ring_stop and ring_msix). Wait for it to finish before +* freeing the ring. */ flush_work (&ring->work);lockdep_unregister_key (&ring->lock_key);@@ -1022,16 +1088,18 @@ enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi)return (enum nhi_fw_mode )val; } -void nhi_interrupt_work (struct work_struct *work) +irqreturn_t nhi_msi_thread (int irq,void *data) { -struct tb_nhi *nhi =container_of (work,typeof (*nhi), interrupt_work); +struct tb_nhi *nhi = data; +LIST_HEAD (completed_frames); +unsigned long flags;int value =0 ;/* Suppress uninitialized usage warning. */ int bit;int hop =-1 ;int type =0 ;/* current interrupt type 0: TX, 1: RX, 2: RX overflow */ struct tb_ring *ring; -spin_lock_irq (&nhi->lock); +spin_lock_irqsave (&nhi->lock, flags);/* * Starting at REG_RING_NOTIFY_BASE there are three status bitfields @@ -1073,17 +1141,28 @@ void nhi_interrupt_work(struct work_struct *work) }spin_lock (&ring->lock); -__ring_interrupt (ring); +/* +* Harvest the completions right away instead of deferring +* to ring->work, so that the RX buffers are reposted without +* another scheduling delay during a burst. +*/ +if (ring->start_poll) +__ring_interrupt (ring); +else if (ring->running) +ring_harvest (ring, &completed_frames);spin_unlock (&ring->lock); } -spin_unlock_irq (&nhi->lock); +spin_unlock_irqrestore (&nhi->lock, flags); + +if (!list_empty (&completed_frames)) +ring_process_completions (&completed_frames); + +return IRQ_HANDLED ; }irqreturn_t nhi_msi (int irq,void *data) { -struct tb_nhi *nhi = data; -schedule_work (&nhi->interrupt_work); -return IRQ_HANDLED ; +return IRQ_WAKE_THREAD ; }static int __nhi_suspend_noirq (struct device *dev,bool wakeup)drivers/thunderbolt/nhi.h +1
-1@@ -31,8 +31,8 @@ int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data);enum nhi_fw_mode nhi_mailbox_mode (struct tb_nhi *nhi);void nhi_enable_int_throttling (struct tb_nhi *nhi);void nhi_disable_interrupts (struct tb_nhi *nhi); -void nhi_interrupt_work (struct work_struct *work);irqreturn_t nhi_msi (int irq,void *data); +irqreturn_t nhi_msi_thread (int irq,void *data);irqreturn_t ring_msix (int irq,void *data);int nhi_probe (struct tb_nhi *nhi);void nhi_shutdown (struct tb_nhi *nhi);drivers/thunderbolt/pci.c +4
-11@@ -206,14 +206,13 @@ static int nhi_pci_init_msi(struct tb_nhi *nhi)if (nvec <0 )return nvec; -INIT_WORK (&nhi->interrupt_work, nhi_interrupt_work); - irq =pci_irq_vector (pdev,0 );if (irq <0 )return irq; - res =devm_request_irq (&pdev->dev, irq, nhi_msi, -IRQF_NO_SUSPEND ,"thunderbolt" , nhi); + res =devm_request_threaded_irq (&pdev->dev, irq, nhi_msi, + nhi_msi_thread, +IRQF_NO_SUSPEND ,"thunderbolt" , nhi);if (res)return res; }@@ -311,14 +310,8 @@ static void nhi_pci_release_irq(struct tb_nhi *nhi)struct tb_nhi_pci *nhi_pci =nhi_to_pci (nhi);struct pci_dev *pdev =to_pci_dev (nhi->dev); -/* -* We have to release the irq before calling flush_work. Otherwise an -* already executing IRQ handler could call schedule_work again. -*/ -if (!pdev->msix_enabled) { +if (!pdev->msix_enabled)devm_free_irq (nhi->dev, pdev->irq, nhi); -flush_work (&nhi->interrupt_work); - }ida_destroy (&nhi_pci->msix_ida); }include/linux/thunderbolt.h +4
-4@@ -501,7 +501,8 @@ void tb_service_properties_changed(struct tb_service *svc);/** * struct tb_nhi - thunderbolt native host interface * @lock: Must be held during ring creation/destruction. Is acquired by -* interrupt_work when dispatching interrupts to individual rings. +* the interrupt thread when dispatching interrupts to individual +* rings. * @dev: Device associated with this NHI instance * @ops: NHI specific optional ops * @iobase: MMIO space of the NHI @@ -511,8 +512,6 @@ void tb_service_properties_changed(struct tb_service *svc);* @going_away: The host controller device is about to disappear so when * this flag is set, avoid touching the hardware anymore. * @iommu_dma_protection: An IOMMU will isolate external-facing ports. -* @interrupt_work: Work scheduled to handle ring interrupt when no -* MSI-X is used. * @hop_count: Number of rings (end point hops) supported by NHI. * @quirks: NHI specific quirks if any * @domain_released: Completed when domain has been fully released @@ -532,7 +531,6 @@ struct tb_nhi {u32 *interrupt_mask;bool going_away;bool iommu_dma_protection; -struct work_struct interrupt_work;u32 hop_count;unsigned long quirks;struct completion domain_released;@@ -639,11 +637,13 @@ enum ring_desc_flags {* @flags: Flags for the frame (see &enum ring_desc_flags) * @eof: End of frame protocol defined field * @sof: Start of frame protocol defined field +* @ring: Ring the frame was completed on */ struct ring_frame {dma_addr_t buffer_phy;ring_cb callback;struct list_head list; +struct tb_ring *ring;u32 size:12 ;u32 flags:12 ;u32 eof:4 ;Signature · 2 lines
-- 2.55.0
RFC PATCH 8/15 thunderbolt: nhi: Add pre_switch_suspend hook
In reply to Konrad DybcioThe Qualcomm router firmware requires a three-way handshake during its suspend routines as the OS writes the SLP bit to a connected device.
Add a hook right beforehand to allow synchronizing right as it happens.
--- drivers/thunderbolt/nhi.h | 2 ++ drivers/thunderbolt/switch.c | 4 ++++ 2 files changed, 6 insertions(+)
drivers/thunderbolt/nhi.h +2 -0
@@ -53,6 +53,7 @@ extern const struct dev_pm_ops nhi_pm_ops;* @release_ring_irq: NHI specific interrupt release hook * @is_present: Whether the device is currently present on the parent bus * @init_interrupts: NHI specific interrupt initialization hook +* @post_switch_suspend: NHI specific hook to call before suspending a switch */ struct tb_nhi_ops {int (*init)(struct tb_nhi *nhi);
@@ -68,6 +69,7 @@ struct tb_nhi_ops {void (*release_ring_irq)(struct tb_ring *ring);bool (*is_present)(struct tb_nhi *nhi);int (*init_interrupts)(struct tb_nhi *nhi); +void (*pre_switch_suspend)(struct tb_nhi *nhi); };/*
drivers/thunderbolt/switch.c +4 -0
@@ -3660,6 +3660,7 @@ int tb_switch_resume(struct tb_switch *sw, bool runtime)*/ void tb_switch_suspend (struct tb_switch *sw,bool runtime) { +struct tb_nhi *nhi = sw->tb->nhi;unsigned int flags =0 ;struct tb_port *port;int err;
@@ -3693,6 +3694,9 @@ void tb_switch_suspend(struct tb_switch *sw, bool runtime)tb_switch_set_wake (sw, flags, runtime); +if (nhi->ops->pre_switch_suspend) + nhi->ops->pre_switch_suspend (nhi); +if (tb_switch_is_usb4 (sw))usb4_switch_set_sleep (sw);else
Signature · 1 line
2.55.0
Re: [PATCH RFC DNM 08/15] thunderbolt: nhi: Add pre_switch_suspend hook
Quoted 16 lines · Konrad Dybcio
The Qualcomm router firmware requires a three-way handshake during its suspend routines as the OS writes the SLP bit to a connected device.
Add a hook right beforehand to allow synchronizing right as it happens.
Signed-off-by Konrad Dybcio <[email protected]>--- drivers/thunderbolt/nhi.h | 2 ++ drivers/thunderbolt/switch.c | 4 ++++ 2 files changed, 6 insertions(+)drivers/thunderbolt/nhi.h +0
-0
drivers/thunderbolt/nhi.h extern const struct dev_pm_ops nhi_pm_ops; · line 56
Quoted 4 lines
drivers/thunderbolt/nhi.h +1
-0@@ -53,6 +53,7 @@ extern const struct dev_pm_ops nhi_pm_ops;* @release_ring_irq: NHI specific interrupt release hook * @is_present: Whether the device is currently present on the parent bus * @init_interrupts: NHI specific interrupt initialization hook +* @post_switch_suspend: NHI specific hook to call before suspending a switch
pre?
Also the tb_nhi_ops starts to look like a collection of random hooks. I would really like there to be some logic in it rather that let's put there everything.
Quoted 16 lines
drivers/thunderbolt/nhi.h +1
-0*/ struct tb_nhi_ops {int (*init)(struct tb_nhi *nhi);@@ -68,6 +69,7 @@ struct tb_nhi_ops {void (*release_ring_irq)(struct tb_ring *ring);bool (*is_present)(struct tb_nhi *nhi);int (*init_interrupts)(struct tb_nhi *nhi); +void (*pre_switch_suspend)(struct tb_nhi *nhi); };/* drivers/thunderbolt/switch.c +0
-0
drivers/thunderbolt/switch.c int tb_switch_resume(struct tb_switch *sw, bool runtime) · line 3663
Quoted 4 lines
drivers/thunderbolt/switch.c +1
-0@@ -3660,6 +3660,7 @@ int tb_switch_resume(struct tb_switch *sw, bool runtime)*/ void tb_switch_suspend (struct tb_switch *sw,bool runtime) { +struct tb_nhi *nhi = sw->tb->nhi;
USB4 side should not call into the NHI like this.
Quoted 16 lines
drivers/thunderbolt/switch.c +3
-0unsigned int flags =0 ;struct tb_port *port;int err;@@ -3693,6 +3694,9 @@ void tb_switch_suspend(struct tb_switch *sw, bool runtime)tb_switch_set_wake (sw, flags, runtime); +if (nhi->ops->pre_switch_suspend) + nhi->ops->pre_switch_suspend (nhi); +if (tb_switch_is_usb4 (sw))usb4_switch_set_sleep (sw);else Signature · 2 lines
-- 2.55.0
RFC PATCH 9/15 thunderbolt: nhi: Resume the domain if the NHI suspend op fails
In reply to Konrad Dybcionhi_suspend_noirq() and nhi_runtime_suspend() suspend the domain first and then call the NHI specific suspend op. If that op fails, the error is returned with the domain still suspended. The control channel is stopped and the switches are marked as suspended, but the PM core treats the device as active: it does not call resume_noirq for a device whose suspend_noirq failed, nor runtime_resume after a failed runtime_suspend. Nothing ever resumes the domain. Hotplug and config space accesses stop working, and the next runtime suspend attempt suspends an already suspended domain.
This happens on Qualcomm USB4 routers whenever the router firmware does not acknowledge the sleep request in time. The op then returns -EBUSY with the router still up.
Resume the domain before returning the error.
--- drivers/thunderbolt/nhi.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/thunderbolt/nhi.c +15 -2
@@ -1177,8 +1177,15 @@ static int __nhi_suspend_noirq(struct device *dev, bool wakeup)if (nhi->ops->suspend_noirq) { ret = nhi->ops->suspend_noirq (tb->nhi, wakeup); -if (ret) +if (ret) { +/* +* The PM core does not call resume_noirq for a +* device whose suspend_noirq failed, so resume +* the domain here. +*/ +tb_domain_resume_noirq (tb);return ret; + } }return 0 ;
@@ -1281,8 +1288,14 @@ static int nhi_runtime_suspend(struct device *dev)if (nhi->ops->runtime_suspend) { ret = nhi->ops->runtime_suspend (tb->nhi); -if (ret) +if (ret) { +/* +* The PM core does not call runtime_resume after a +* failed runtime_suspend, so resume the domain here. +*/ +tb_domain_runtime_resume (tb);return ret; + } }return 0 ; }
Signature · 1 line
2.55.0
Re: [PATCH RFC DNM 09/15] thunderbolt: nhi: Resume the domain if the NHI suspend op fails
Hi,
Quoted 4 lines · Konrad Dybcio
nhi_suspend_noirq()andnhi_runtime_suspend()suspend the domain first and then call the NHI specific suspend op. If that op fails, the error is returned with the domain still suspended. The control channel is stopped and the switches are marked as suspended, but the PM core
routers
Note once the domain sleep is started, there is no way going back until it enters sleep.
Quoted 9 lines
treats the device as active: it does not call
resume_noirqfor a device whosesuspend_noirqfailed, norruntime_resumeafter a failedruntime_suspend. Nothing ever resumes the domain. Hotplug and config space accesses stop working, and the next runtime suspend attempt suspends an already suspended domain.This happens on Qualcomm USB4 routers whenever the router firmware does not acknowledge the sleep request in time. The op then returns
-EBUSYwith the router still up.
Is there a reason why the firmware does not ack it in time?
RFC PATCH 10/15 thunderbolt: nhi: Resume a runtime suspended NHI for system suspend
In reply to Konrad DybcioThe PCI core resumes a runtime suspended device in pci_pm_suspend() before calling the driver's suspend callback, so nhi_suspend_noirq() always finds the NHI active. Platform devices get no such treatment, so these runtime suspended NHIs gets suspended a second time in the noirq phase and resumed in nhi_resume_noirq(). nhi_complete() then still sees it as runtime suspended and resumes it once more, which corrupts the control channel (RX checksum mismatches, config space timeouts).
Resume the NHI at the beginning of nhi_suspend(), like the PCI core does as a workaround.
--- drivers/thunderbolt/nhi.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/thunderbolt/nhi.c +7 -0
@@ -1258,6 +1258,13 @@ static int nhi_suspend(struct device *dev) {struct tb *tb =dev_get_drvdata (dev); +/* +* The noirq callbacks expect the NHI to be active. The PCI core +* resumes a runtime suspended device before calling this, do the +* same for the NHIs that are not PCI devices. +*/ +pm_runtime_resume (dev); +return tb_domain_suspend (tb); }
Signature · 1 line
2.55.0
Re: [PATCH RFC DNM 10/15] thunderbolt: nhi: Resume a runtime suspended NHI for system suspend
Hi,
Quoted 10 lines · Konrad Dybcio
The PCI core resumes a runtime suspended device in
pci_pm_suspend()before calling the driver's suspend callback, sonhi_suspend_noirq()always finds the NHI active. Platform devices get no such treatment, so these runtime suspended NHIs gets suspended a second time in the noirq phase and resumed innhi_resume_noirq().nhi_complete()then still sees it as runtime suspended and resumes it once more, which corrupts the control channel (RX checksum mismatches, config space timeouts).Resume the NHI at the beginning of
nhi_suspend(), like the PCI core does as a workaround.
Okay but I would rather keep it suspended over the system sleep. There is no difference from USB4 perspective so there is really no point waking it up. IIRC we do that now because USB stack needs to re-configure wakes for S3 but for s2idle (which is what the modern Intel systems at least do) that should not be necessary - it should wake the same way as runtime suspended.
Quoted 26 lines
Signed-off-by Konrad Dybcio <[email protected]>--- drivers/thunderbolt/nhi.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/thunderbolt/nhi.c +7
-0@@ -1258,6 +1258,13 @@ static int nhi_suspend(struct device *dev) {struct tb *tb =dev_get_drvdata (dev); +/* +* The noirq callbacks expect the NHI to be active. The PCI core +* resumes a runtime suspended device before calling this, do the +* same for the NHIs that are not PCI devices. +*/ +pm_runtime_resume (dev); +return tb_domain_suspend (tb); }Signature · 2 lines
-- 2.55.0
RFC PATCH 11/15 thunderbolt: Raise TB_TIMEOUT to 500 ms
In reply to Konrad DybcioRouters with firmware-managed link training (e.g. Qualcomm) can take well over 100 ms to answer config requests while a link is coming up. Increase the timeout to facilitate that.
--- drivers/thunderbolt/tb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/tb.c +1 -1
@@ -16,7 +16,7 @@#include "tb_regs.h" #include "tunnel.h" -#define TB_TIMEOUT 100/* ms */ +#define TB_TIMEOUT 500/* ms */ #define TB_RELEASE_BW_TIMEOUT 10000/* ms */ /*
Signature · 1 line
2.55.0
RFC PATCH 12/15 thunderbolt: Refuse to activate DP/USB3/PCIe tunnels
In reply to Konrad DybcioThis is for demonstration purposes for anyone wanting to try out the series on real hw, keeping in mind the constraints detailed in the cover letter.
--- drivers/thunderbolt/tunnel.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/thunderbolt/tunnel.c +2 -0
@@ -2430,6 +2430,8 @@ int tb_tunnel_activate(struct tb_tunnel *tunnel)int res, i;tb_tunnel_dbg (tunnel,"activating\n" ); +if (!tb_tunnel_is_dma (tunnel)) +return -EOPNOTSUPP ;/* * Make sure all paths are properly disabled before enabling
Signature · 1 line
2.55.0
RFC PATCH 13/15 thunderbolt: Introduce Qualcomm USB4 router driver
In reply to Konrad DybcioIntroduce a driver for the in-house Qualcomm USB4 router driver. It consists of resource enablement, uC firmware loading and communication, Type-C infrastructure and power state handling.
Unlike many other implementations, the power state of both the router and the native protocol controllers has to be manually coordinated, which much of this driver ends up doing.
--- drivers/thunderbolt/Kconfig | 13 + drivers/thunderbolt/Makefile | 3 + drivers/thunderbolt/eeprom.c | 17 - drivers/thunderbolt/qcom.c | 2299 +++++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/qcom.h | 251 +++++ drivers/thunderbolt/tb.h | 20 + drivers/thunderbolt/tb_regs.h | 3 + 7 files changed, 2589 insertions(+), 17 deletions(-)
drivers/thunderbolt/Kconfig +13 -0
@@ -64,6 +64,19 @@ config USB4_DMA_TEST To compile this driver a module, choose M here. The module will be called thunderbolt_dma_test. +config USB4_QCOM + tristate "Qualcomm USB4/Thunderbolt Support" + depends on USB4 + depends on OF + depends on ARCH_QCOM || COMPILE_TEST + depends on COMMON_CLK && PM + help + Say Y here to add support for the USB4 and Thunderbolt host + routers found on Qualcomm SoCs. + + To compile the driver as a module, choose M here. The module + will be called thunderbolt_qcom. + config USB4_STREAM tristate "Stream data over Thunderbolt/USB4 cable" depends on USB4_CONFIGFS
drivers/thunderbolt/Makefile +3 -0
@@ -11,6 +11,9 @@ thunderbolt-$(CONFIG_USB4_CONFIGFS) += configfs.o thunderbolt-${CONFIG_USB4_KUNIT_TEST} += test.o CFLAGS_test.o += $(DISABLE_STRUCTLEAK_PLUGIN) +thunderbolt_qcom-objs := qcom.o +obj-${CONFIG_USB4_QCOM} += thunderbolt_qcom.o + thunderbolt_dma_test-${CONFIG_USB4_DMA_TEST} += dma_test.o obj-$(CONFIG_USB4_DMA_TEST) += thunderbolt_dma_test.o
drivers/thunderbolt/eeprom.c +0 -17
@@ -197,23 +197,6 @@ static int tb_eeprom_read_n(struct tb_switch *sw, u16 offset, u8 *val,return tb_eeprom_active (sw, false); } -static u8 tb_crc8 (u8 *data,int len) -{ -int i, j; -u8 val =0xff ; -for (i =0 ; i < len; i++) { - val ^= data[i]; -for (j =0 ; j <8 ; j++) - val = (val <<1 ) ^ ((val &0x80 ) ?7 :0 ); - } -return val; -} - -static u32 tb_crc32 (void *data,size_t len) -{ -return ~crc32c (~0 , data, len); -} -#define TB_DROM_DATA_START 13#define TB_DROM_HEADER_SIZE 22#define USB4_DROM_HEADER_SIZE 16
drivers/thunderbolt/qcom.c new file +2299 -0
2,299 lines not on this page · raw message
drivers/thunderbolt/qcom.h new file +251 -0
251 lines not on this page · raw message
drivers/thunderbolt/tb.h +20 -0
@@ -9,6 +9,7 @@#ifndef TB_H_ #define TB_H_ +#include <linux/crc32.h> #include <linux/debugfs.h> #include <linux/nvmem-provider.h> #include <linux/pci.h>
@@ -1330,6 +1331,25 @@ static inline bool tb_switch_is_usb4(const struct tb_switch *sw)return usb4_switch_version (sw) >0 ; } +static inline u8 tb_crc8 (u8 *data,int len) +{ +int i, j; +u8 val =0xff ; + +for (i =0 ; i < len; i++) { + val ^= data[i]; +for (j =0 ; j <8 ; j++) + val = (val <<1 ) ^ ((val &0x80 ) ?7 :0 ); + } + +return val; +} + +static inline u32 tb_crc32 (void *data,size_t len) +{ +return ~crc32c (~0 , data, len); +} +void usb4_switch_check_wakes (struct tb_switch *sw);int usb4_switch_setup (struct tb_switch *sw);int usb4_switch_configuration_valid (struct tb_switch *sw);
drivers/thunderbolt/tb_regs.h +3 -0
@@ -193,6 +193,7 @@ struct tb_regs_switch_header {#define USB4_VERSION_MAJOR_MASK GENMASK(7, 5)#define ROUTER_CS_1 0x01 +#define ROUTER_CS_1_UA GENMASK(13, 8)#define ROUTER_CS_3 0x03#define ROUTER_CS_3_V BIT(31)#define ROUTER_CS_4 0x04
@@ -388,6 +389,7 @@ struct tb_regs_port_header {#define PORT_CS_18_WOCS BIT(16)#define PORT_CS_18_WODS BIT(17)#define PORT_CS_18_WOU4S BIT(18) +#define PORT_CS_18_WOIDS BIT(19)#define PORT_CS_18_CSA BIT(22)#define PORT_CS_18_TIP BIT(24)#define PORT_CS_19 0x13
@@ -397,6 +399,7 @@ struct tb_regs_port_header {#define PORT_CS_19_WOC BIT(16)#define PORT_CS_19_WOD BIT(17)#define PORT_CS_19_WOU4 BIT(18) +#define PORT_CS_19_WOID BIT(19)#define PORT_CS_19_START_ASYM BIT(24)/* Display Port adapter registers */
Signature · 1 line
2.55.0
Re: [PATCH RFC DNM 13/15] thunderbolt: Introduce Qualcomm USB4 router driver
On Tue, Nov 24, 2026 at 21:01:42 +0100, Konrad Dybcio wrote:
[..]
Quoted 11 lines
drivers/thunderbolt/qcom.c new file +11
-0+static int qcom_usb4_mux_set (struct typec_mux_dev *mux,struct typec_mux_state *state) +{ +struct qcom_usb4 *qcusb4 =typec_mux_get_drvdata (mux); +struct qcusb4_link_req req = { .usb4 = true }; +struct typec_thunderbolt_data *tbt_data; +struct enter_usb_data *usb4_data; + +guard (mutex)(&qcusb4->typec_lock); + +if (state->alt && state->alt->svid ==USB_TYPEC_TBT_SID ) { + req.phy_submode =PHY_SUBMODE_TBT3 ;
drivers/thunderbolt/qcom.c line 1778
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+ + tbt_data = state->data; + + req.cable_max_gen =TBT_CABLE_SPEED (tbt_data->cable_mode); + +if (FIELD_GET (TBT_CABLE_ACTIVE_PASSIVE , tbt_data->cable_mode)) { + req.active_cable = true; + req.cable_legacy_tbt3 = true; + } + }else if (state->mode ==TYPEC_MODE_USB4 ) {
While testing this series on an ASUS Zenbook A16 (UX3607OA), I ran into an issue with a USB type-c display using DP Alt Mode.
TYPEC_MODE_USB4 and TYPEC_DP_STATE_C share the same integer value, causing a DP Alt Mode request to be interpreted as a USB4 request.
Changing the above condition to
} else if (!state->alt && state->mode == TYPEC_MODE_USB4) {fixes the issue. The display works again with both USB-C ports.
drivers/thunderbolt/qcom.c line 1804
Quoted 4 lines
drivers/thunderbolt/qcom.c new file +4
-0+ }else { +/* Do nothing for e.g. DP altmode */ +return 0 ; + }
Regards,
Troels
Re: [PATCH RFC DNM 13/15] thunderbolt: Introduce Qualcomm USB4 router driver
In reply to Konrad DybcioHi,
Quoted 71 lines · Konrad Dybcio
Introduce a driver for the in-house Qualcomm USB4 router driver. It consists of resource enablement, uC firmware loading and communication, Type-C infrastructure and power state handling.
Unlike many other implementations, the power state of both the router and the native protocol controllers has to be manually coordinated, which much of this driver ends up doing.
Signed-off-by Konrad Dybcio <[email protected]>--- drivers/thunderbolt/Kconfig | 13 + drivers/thunderbolt/Makefile | 3 + drivers/thunderbolt/eeprom.c | 17 - drivers/thunderbolt/qcom.c | 2299 +++++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/qcom.h | 251 +++++ drivers/thunderbolt/tb.h | 20 + drivers/thunderbolt/tb_regs.h | 3 + 7 files changed, 2589 insertions(+), 17 deletions(-)drivers/thunderbolt/Kconfig +13
-0@@ -64,6 +64,19 @@ config USB4_DMA_TEST To compile this driver a module, choose M here. The module will be called thunderbolt_dma_test. +config USB4_QCOM + tristate "Qualcomm USB4/Thunderbolt Support" + depends on USB4 + depends on OF + depends on ARCH_QCOM || COMPILE_TEST + depends on COMMON_CLK && PM + help + Say Y here to add support for the USB4 and Thunderbolt host + routers found on Qualcomm SoCs. + + To compile the driver as a module, choose M here. The module + will be called thunderbolt_qcom. + config USB4_STREAM tristate "Stream data over Thunderbolt/USB4 cable" depends on USB4_CONFIGFSdrivers/thunderbolt/Makefile +3
-0@@ -11,6 +11,9 @@ thunderbolt-$(CONFIG_USB4_CONFIGFS) += configfs.o thunderbolt-${CONFIG_USB4_KUNIT_TEST} += test.o CFLAGS_test.o += $(DISABLE_STRUCTLEAK_PLUGIN) +thunderbolt_qcom-objs := qcom.o +obj-${CONFIG_USB4_QCOM} += thunderbolt_qcom.o + thunderbolt_dma_test-${CONFIG_USB4_DMA_TEST} += dma_test.o obj-$(CONFIG_USB4_DMA_TEST) += thunderbolt_dma_test.odrivers/thunderbolt/eeprom.c +0
-6@@ -197,23 +197,6 @@ static int tb_eeprom_read_n(struct tb_switch *sw, u16 offset, u8 *val,return tb_eeprom_active (sw, false); } -static u8 tb_crc8 (u8 *data,int len) -{ -int i, j; -u8 val =0xff ; -for (i =0 ; i < len; i++) { - val ^= data[i];
drivers/thunderbolt/eeprom.c static int tb_eeprom_read_n(struct tb_switch *sw, u16 offset, u8 *val, · line 215
Quoted 10 lines
drivers/thunderbolt/eeprom.c +0
-10-for (j =0 ; j <8 ; j++) - val = (val <<1 ) ^ ((val &0x80 ) ?7 :0 ); - } -return val; -} - -static u32 tb_crc32 (void *data,size_t len) -{ -return ~crc32c (~0 , data, len); -}
Maybe make this separate preparatory patch?
Quoted 37 lines
drivers/thunderbolt/eeprom.c +0
-1-#define TB_DROM_DATA_START 13#define TB_DROM_HEADER_SIZE 22#define USB4_DROM_HEADER_SIZE 16drivers/thunderbolt/qcom.c new file +27
-0@@ -0,0 +1,2299 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +*/ + +#include <linux/align.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/devm-helpers.h> +#include <linux/errno.h> +#include <linux/firmware.h> +#include <linux/interrupt.h> +#include <linux/iopoll.h> +#include <linux/mfd/syscon.h> +#include <linux/module.h> +#include <linux/overflow.h> +#include <linux/phy/phy.h> +#include <linux/pinctrl/consumer.h> +#include <linux/platform_device.h> +#include <linux/pm_domain.h> +#include <linux/pm_opp.h> +#include <linux/pm_runtime.h> +#include <linux/pm_wakeirq.h> +#include <linux/property.h> +#include <linux/regmap.h> +#include <linux/reset.h>
drivers/thunderbolt/qcom.c line 37
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+#include <linux/slab.h> +#include <linux/soc/qcom/smem.h> +#include <linux/unaligned.h> +#include <linux/units.h> +#include <linux/usb/pd.h> +#include <linux/usb/typec_altmode.h> +#include <linux/usb/typec_mux.h> +#include <linux/usb/typec_tbt.h> +#include <linux/usb/typec.h> +#include <linux/workqueue.h>
Are you sure you need all of these?
drivers/thunderbolt/qcom.c line 48
Quoted 11 lines
drivers/thunderbolt/qcom.c new file +11
-0+ +#include "nhi.h" +#include "nhi_regs.h" +#include "qcom.h" +#include "tb.h" + +/* +* The router's operational ability is directly tied to the mode and power state of the QMPPHY +* (and thus to cable presence). The router (transitively) sources its clocks from the PHY, +* although it may operate in reduced capacity even when it's off (by muxing its inputs to the +* 19.2 MHz XO clock source). That 'reduced mode' allows for register access, but not TBT linkup.
TB or Thunderbolt
Ditto everywhere
Quoted 23 lines
drivers/thunderbolt/qcom.c new file +23
-0+* +* At probe time, that mechanism is used to bootstrap the router regardless of the plug state +* (since forcefully switching the PHY to USB4 mode would disrupt a USB3/DP link on that port). +* Then, upon a USB4/TBT3 typec_mux event the PHY is reconfigured, the clocks are reconfigured to +* follow, the uC is brought online and a BEGIN_HSE command is sent to the router, which can take +* a couple seconds to complete. +* +* Upon unplug, the router has to be immediately torn down (including the clocks scaffolding and +* the PHY) to unblock the port for a potentially soon-to-be-plugged USB3/DP device. +* +* Suspend/resume sequences require a handshake with the uC, as that influences the state of some +* clocks and failing to follow that ends up in a hard crash of the entire platform. +* +* This is modeled as an explicit state machine (enum qcusb4_hw_state), with all transitions +* serialized by state_lock: +* +* OFF --probe--> IDLE <--reconcile--> LINK +* \ / +* +---> ASLEEP <----+ (runtime/system sleep, uC handshake) +* +* The Type-C callbacks record what state they want (->desired_state) and kick the reconcile work, +* which runs the IDLE <-> LINK transitions. Cable removal is LINK -> IDLE, which cycles the domain +* and the router through a full sleep (TBT layer _SLP first, then the uC handshake) to hand the PHY
drivers/thunderbolt/qcom.c line 81
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+* back, then cold-restarts the router on XO (a sleep exit would have the FW go for the PHY it no +* longer has), so the TBT core sees a regular unplug. The PHY must never be taken away outside of +* that handshake. For the same reason, sleep entered from IDLE is exited through a cold restart, as +* the cable may have been plugged in meanwhile. Two gates protect against unclocked access from +* outside the state machine: uc_online for FW commands and mmio_ok for the PCIe reset controller. +*/ + +/* ROUTER_CS registers */ +#define ROUTER_CS_CS_1 0x4 +#define ROUTER_CS_CS_5 0x14
CS_CS? And we do have ROUTER_CS alread in tb_regs.h. If these are not the same perhaps prefix them QCOM_ or so to avoid confusion?
drivers/thunderbolt/qcom.c line 83
Quoted 2 lines
drivers/thunderbolt/qcom.c new file +2
-0+ +#define is_usb4v2 (q) ((q)->match_data->entries[(q)->instance_idx].usb4v2_capable)
Maybe inline function instead to make this somewhat more readable.
drivers/thunderbolt/qcom.c line 94
Quoted 11 lines
drivers/thunderbolt/qcom.c new file +11
-0+ +/* LANEn_CS registers */ +#define UC_RAM_DROM_OFFSET_V1 0xdf20 +#define UC_RAM_DROM_OFFSET_V2 0xff20 +#define UC_RAM_DROM_OFFSET (q) (is_usb4v2((q)) ? \ + UC_RAM_DROM_OFFSET_V2 : UC_RAM_DROM_OFFSET_V1) + +#define LANEn_CS_CS_1 (q) (is_usb4v2(q) ? 0x58 : 0x50) +#define LANEn_CS_CS_1_ADAPTER_STATE GENMASK(29, 26) +#define LANEn_CS_CS_18 (q) (is_usb4v2(q) ? 0xac : 0xa4) +#define LANEn_CS_CS_19 (q) (is_usb4v2(q) ? 0xb0 : 0xa8)
Here also depending on where these are used but maybe more readable is to have a separate function or block.
drivers/thunderbolt/qcom.c line 100
Quoted 6 lines
drivers/thunderbolt/qcom.c new file +6
-0+ +/* PORT_GROUP registers */ +#define PORT_GROUP_LANE_CFG 0x0 +#define LANE_CFG_CLx_SUPPORT (q) (is_usb4v2(q) ? GENMASK(21, 19) : GENMASK(23, 21)) +#define PORT_GROUP_FCM_2_CFG 0x64 +#define FCM_2_CFG_DIS_ANY_HOPID BIT(6)
I prefer not to indent these. Let's try to be consistent across.
Quoted 38 lines
drivers/thunderbolt/qcom.c new file +38
-0+ +/* SIDEBAND registers */ +#define SIDEBAND_TX_CTRL 0xc +#define SB_TX_CTRL_TX_ENABLE BIT(31) + +/* UC_PER registers */ +#define UC_PER_CONTROL 0x1000 +#define PER_CONTROL_UC_ENABLE BIT(0) +#define UC_PER_SW_TRIGGERS_UC_IRQ 0x100c +#define UC_PER_FW_INT_STATUS_SET 0x1010 +#define UC_PER_FW_INT_CLR 0x1018 +#define PER_FW_INT_CLR_CLR BIT(0) +#define UC_PER_FW_INT_MASK 0x101c +#define PER_FW_INT_MASK_FW_INT BIT(0) + +/* CFG registers */ +#define CFG_SYS_CLK_CGC 0x0 +#define SYS_CLK_CGC_SYS_CLK_EN_USBAP BIT(7) + +/* USBAP_CONFIG registers */ +#define USBAP_CFG_SYNC_RST_USB3 0x0 +#define RST_USB3_RST BIT(0) +#define USBAP_CFG_USB4_MODE 0x4 +#define USB4_MODE_USB4_MODE BIT(0) +#define USBAP_CFG_RXTERM_BACKDOOR_CTRL 0x10 +#define USBAP_CFG_RXTERM_BACKDOOR_STS 0x14 +#define RXTERM_RX_TERM BIT(0) +#define USBAP_CFG_PHYSTATUS_EN 0x18 +#define PHYSTATUS_EN_EN BIT(0) + +/* PCIEAP_CONFIG registers */ +#define PCIEAP_CONFIG_SYNC_RST 0x0 +#define PCIEAP_SYNC_RST_PCIE BIT(0) +#define PCIEAP_CONFIG_IRQ_STATUS 0x0c +#define PCIEAP_IRQ_PE_DEASSERT BIT(3) +#define PCIEAP_IRQ_PE_ASSERT BIT(2) +#define PCIEAP_CONFIG_IRQ_MASK 0x10 +#define PCIEAP_CONFIG_IRQ_CLEAR 0x14
drivers/thunderbolt/qcom.c line 148
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+ +/* PCIEAP (USB4 v2 router) registers */ +#define PCIEAP_TX_CFG 0x0 +#define PCIEAP_TX_CFG_EN_FLUSH_MISSING_SOP BIT(22) + +/* ROUTER_CONFIG registers */ +#define ROUTER_CONFIG_CS_6 0x18 +#define CS_6_ROUTER_READY BIT(24) +#define ROUTER_CONFIG_CS_7 0x1c +#define ROUTER_CONFIG_CS_8 0x20
Also ROUTER_CONFIG_CS and ROUTER_CS_CS? Its fine if these match the datasheet but if you invented them then I suggest rethink the naming so that it's not that confusing ;-)
drivers/thunderbolt/qcom.c line 153
Quoted 5 lines
drivers/thunderbolt/qcom.c new file +5
-0+ +struct qcom_usb4_fw_event { +u8 opcode; +u8 params[]; +} __packed;
Please check if you really need the __packed.
Quoted 6 lines
drivers/thunderbolt/qcom.c new file +6
-0+struct qcom_usb4_fw_events { +__le16 num_entries; +__le16 entry_size; +__le32 next_entry_index; +__le16 num_unread_entries;/* This only guarantees num_unread >= num_entries */ +u8 res[6 ];
drivers/thunderbolt/qcom.c line 170
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+struct qcom_usb4_fw_event entries[]; +} __packed; + +#define FW_EV_BUF_SIZE SZ_8K + +enum qcom_usb4_fw_cmd { +FW_CMD_BEGIN_HSE =0x1 , + +FW_CMD_ENABLE_PHY_PRESETS =0x2 , +#define PHY_PRESETS_DEFAULT (BIT(0) | BIT(1) | BIT(5) | BIT(6) | BIT(10) | BIT(11))
Also perhaps move these outside of the enum?
And while there maybe kernel-doc?
Quoted 11 lines
drivers/thunderbolt/qcom.c new file +11
-0+ + FW_CMD_LIMIT_LOGLEVEL = 0x3, +#define LOG_LEVEL_ALL 0 +#define LOG_LEVEL_WARN 1 +#define LOG_LEVEL_ERR 2 +#define LOG_LEVEL_NONE 3 + +/* Only makes sense to call this after FW_MSG_SLEEP_READY */ + FW_CMD_COMPLETE_SLEEP = 0x4, + +/* Reconfigure the internals to restore the link (or handle an in-sleep disconnect) */
drivers/thunderbolt/qcom.c line 191
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+ FW_CMD_WAKEUP = 0x5, +#define WAKEUP_REASON_DEVICE 0 +#define WAKEUP_REASON_CBL_DIS 1 +#define WAKEUP_REASON_CBL_CON 2 +#define WAKEUP_REASON_SYSTEM 3 + +/* The router alone can't differentiate between physical and logical disconnects */ +FW_CMD_PHYS_DISCONNECT =0x6 , + + FW_CMD_DEPRECATED = 0x7,
This is not used anywhere so drop it (also ditto similar if there are).
Quoted 4 lines
drivers/thunderbolt/qcom.c new file +4
-0+ +/* USB4v2 introduced more tuning presets */ + FW_CMD_ENABLE_PHY_PRESETS_MSB = 0x8, +
drivers/thunderbolt/qcom.c line 205
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+/* Notify the uC that we're done with the Host Router Reset */ + FW_CMD_HRR_DONE = 0x9, + + FW_CMD_WA_DONE = 0xa, +#define WA_DONE_USBAP_RXTERM 1 +}; + +/* Must be called with the mux clocks enabled */ +static int qcusb4_select_rx_clock_source (struct qcom_usb4 *qcusb4, +bool fast_clock)
qcom_usb4_?
drivers/thunderbolt/qcom.c line 218
Quoted 13 lines
drivers/thunderbolt/qcom.c new file +13
-0+{ +struct clk *rx0 = qcusb4->mux_clks[MUX_CLK_PHY_RX0 ].clk; +struct clk *rx1 = qcusb4->mux_clks[MUX_CLK_PHY_RX1 ].clk; +unsigned long rate = fast_clock ?ULONG_MAX :19200000 ; +int ret; + +clk_disable_unprepare (rx0); +clk_disable_unprepare (rx1); + +/* No error unwinding on purpose, failure here is borderline impossible and catastrophic */ + ret =clk_set_rate (rx0, rate); +if (ret) { +dev_err (qcusb4->nhi.dev,"Failed to select RX0 clock source: %d\n" , ret);
"failed .."
To be consistent with the rest of the driver.
Ditto everywhere.
Quoted 8 lines
drivers/thunderbolt/qcom.c new file +8
-0+return ret; + } + + ret =clk_set_rate (rx1, rate); +if (ret) { +dev_err (qcusb4->nhi.dev,"Failed to select RX1 clock source: %d\n" , ret); +return ret; + }
drivers/thunderbolt/qcom.c line 236
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+ + ret =clk_prepare_enable (rx0); +if (ret) { +dev_err (qcusb4->nhi.dev,"Failed to re-enable the RX0 clock: %d\n" , ret); +return ret; + } + + ret =clk_prepare_enable (rx1); +if (ret) +dev_err (qcusb4->nhi.dev,"Failed to re-enable the RX1 clock: %d\n" , ret);
It's fine if these fail that they are set to prepared and configured?
drivers/thunderbolt/qcom.c line 241
Quoted 5 lines
drivers/thunderbolt/qcom.c new file +5
-0+ +return ret; +} + +static int __qcusb4_fw_cmd (struct qcom_usb4 *qcusb4,enum qcom_usb4_fw_cmd msg,u32 args)
__qcom_usb4_?
drivers/thunderbolt/qcom.c line 252
Quoted 11 lines
drivers/thunderbolt/qcom.c new file +11
-0+{ +u32 cmd; +u32 val; + +lockdep_assert_held (&qcusb4->uc_cmd_lock); + +/* The uC is either down, or about to be */ +if (!qcusb4->uc_online) { +dev_warn_ratelimited (qcusb4->nhi.dev, +"Dropping cmd=0x%x arg=0x%x, the uC is not running\n" , + msg, args);
Does this happen how often? Is ratelimited needed? Maybe this can be debug instead or drop completely?
drivers/thunderbolt/qcom.c line 264
Quoted 12 lines
drivers/thunderbolt/qcom.c new file +12
-0+return -EAGAIN ; + } + +pm_runtime_mark_last_busy (qcusb4->nhi.dev); + + cmd =FIELD_PREP (GENMASK (31 ,8 ), args) | +FIELD_PREP (GENMASK (7 ,0 ), msg); + +writel (cmd, qcusb4->uc_per +UC_PER_SW_TRIGGERS_UC_IRQ ); + +if (readl_poll_timeout (qcusb4->uc_per +UC_PER_SW_TRIGGERS_UC_IRQ , + val, !val,10 ,10 *USEC_PER_MSEC )) {
Maybe #define for the timeout?
Quoted 14 lines
drivers/thunderbolt/qcom.c new file +14
-0+dev_err (qcusb4->nhi.dev,"Firmware failed to clear cmd 0x%08x\n" , cmd); +return -ETIMEDOUT ; + } + +return 0 ; +} + +static int qcusb4_fw_cmd (struct qcom_usb4 *qcusb4,enum qcom_usb4_fw_cmd msg,u32 args) +{ +guard (mutex)(&qcusb4->uc_cmd_lock); + +return __qcusb4_fw_cmd (qcusb4, msg, args); +} +
drivers/thunderbolt/qcom.c line 288
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+/* +* Send a command that the FW acks with an event. The completion is re-armed under uc_cmd_lock, +* so that a stale ack from an earlier command can't satisfy the wait. +*/ +static int qcusb4_fw_cmd_wait (struct qcom_usb4 *qcusb4,enum qcom_usb4_fw_cmd msg,u32 args, +struct completion *done,unsigned int timeout_ms) +{ +int ret; + + scoped_guard(mutex, &qcusb4->uc_cmd_lock) {
int ret;
drivers/thunderbolt/qcom.c line 290
Quoted 2 lines
drivers/thunderbolt/qcom.c new file +2
-0+reinit_completion (done); +
Drop this empty line.
Quoted 6 lines
drivers/thunderbolt/qcom.c new file +6
-0+ ret =__qcusb4_fw_cmd (qcusb4, msg, args); +if (ret) +return ret; + } + +if (!wait_for_completion_timeout (done,msecs_to_jiffies (timeout_ms)))
drivers/thunderbolt/qcom.c line 306
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+return -ETIMEDOUT ; + +return 0 ; +} + +enum qcom_usb4_fw_msg { +FW_MSG_MESSAGE =0x1 , +FW_MSG_ERR =0x2 , +FW_MSG_TEST_RES =0x3 , +/* Fires after a successful handling of FW_CMD_COMPLETE_SLEEP */
You can use kernel-doc as well to document these.
Quoted 8 lines
drivers/thunderbolt/qcom.c new file +8
-0+FW_MSG_SLEEP_DONE =0x4 , +/* Fires after a packet with opcode = USB4_SB_OPCODE_ROUTER_OFFLINE is handled */ +FW_MSG_EXIT_OFFLINE =0x5 , +/* Fires after any sort of (incl. logical) disconnect has been detected */ +FW_MSG_DISCONNECT =0x6 , +/* Fires after a successful handling of ROUTER_CS_5.SLP becoming set */ + FW_MSG_SLEEP_READY = 0x7, +/* "A specific software workaround must be applied immediately" */
drivers/thunderbolt/qcom.c line 324
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+ FW_MSG_TRIGGER = 0x8, +#define WA_TRIGGER_USBAP_RXTERM 3 + +/* "found hotplug with HopId > 1" */ +FW_MSG_CHAINED_HOTPLUG =0x9 , +/* Fires after a HRR request arrives, needs to be acked with FW_CMD_HRR_DONE */ +FW_MSG_HOST_RESET =0xa , +FW_MSG_HSE_STATS =0xb , + FW_MSG_FOM_STATS = 0xc, +};
Move this to the top of the file.
Quoted 7 lines
drivers/thunderbolt/qcom.c new file +7
-0+ +static void qcom_usb4_fw_clear_irq (struct qcom_usb4 *qcusb4) +{ +/* Clear the irq - this resets the unread message counter on the FW side */ +writel (PER_FW_INT_CLR_CLR , qcusb4->uc_per +UC_PER_FW_INT_CLR ); +readl (qcusb4->uc_per +UC_PER_FW_INT_CLR ); +}
drivers/thunderbolt/qcom.c line 341
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+ +static bool qcom_usb4_fw_event_ring_valid (struct qcom_usb4 *qcusb4,u32 data_off, +u16 total_entries,u16 entry_size,u32 *ring_size) +{ +u32 entries_size; + +if (!total_entries || entry_size <sizeof (struct qcom_usb4_fw_event )) +return false; + +if (check_mul_overflow ((u32 )total_entries, (u32 )entry_size, &entries_size))
You really need the casts here and below?
drivers/thunderbolt/qcom.c line 346
Quoted 5 lines
drivers/thunderbolt/qcom.c new file +5
-0+return false; + +if (check_add_overflow ((u32 )sizeof (struct qcom_usb4_fw_events ), + entries_size, ring_size)) +return false;
Functions that modify the passed parameters should do so only when they actually succeed.
drivers/thunderbolt/qcom.c line 359
Quoted 13 lines
drivers/thunderbolt/qcom.c new file +13
-0+ +if (*ring_size >FW_EV_BUF_SIZE ) +return false; + +if (data_off > qcusb4->uc_ram_size - *ring_size) +return false; + +return true; +} + +/* +* The FW exposes a ring buffer with no 'event processing done' acking (i.e. the event may be gone +* before we process it).
I think you should wrap these.
Quoted 4 lines
drivers/thunderbolt/qcom.c new file +4
-0+* +* Accessing that data happens by directly reading the uC's RAM at a given offset. +* The uC is clocked by the SYS clock (part of qcusb4->mux_clks), so care must be taken to disable +* this IRQ, to prevent system crashes.
drivers/thunderbolt/qcom.c line 373
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+*/ +static irqreturn_t qcom_usb4_fw_irq_handler (int irq,void *data) +{ +struct qcom_usb4 *qcusb4 = data; +u16 total_entries; +u16 entry_size; +u32 ring_size; +u32 data_off; + +if (unlikely (!qcusb4->fw_ev_rb_base)) {
Drop the unlikely.
It reads better actually if you do:
if (qcusb4->fw_ev_rb_base) return IRQ_WAKE_THREAD; data_off = readl(qcusb4->uc_per + UC_PER_FW_INT_STATUS_SET); ...
Quoted 72 lines
drivers/thunderbolt/qcom.c new file +72
-0+ data_off =readl (qcusb4->uc_per +UC_PER_FW_INT_STATUS_SET ); +if (!IS_ALIGNED (data_off,sizeof (u32)) || + data_off > qcusb4->uc_ram_size -sizeof (struct qcom_usb4_fw_events )) { +dev_err_ratelimited (qcusb4->nhi.dev, +"Invalid FW event ring offset 0x%x\n" , + data_off); +qcom_usb4_fw_clear_irq (qcusb4); +return IRQ_HANDLED ; + } + + total_entries =lower_16_bits (readl (qcusb4->uc_ram + data_off)); + entry_size =upper_16_bits (readl (qcusb4->uc_ram + data_off)); + +if (!qcom_usb4_fw_event_ring_valid (qcusb4, data_off, total_entries, + entry_size, &ring_size)) { +dev_err_ratelimited (qcusb4->nhi.dev, +"Invalid FW event ring: off=0x%x entries=%u size=%u\n" , + data_off, total_entries, entry_size); +qcom_usb4_fw_clear_irq (qcusb4); +return IRQ_HANDLED ; + } + + qcusb4->fw_ev_rb_base = qcusb4->uc_ram + data_off; + qcusb4->fw_ev_total_entry_num = total_entries; + qcusb4->fw_ev_entry_size = entry_size; + qcusb4->fw_ev_ring_size = ring_size; + qcusb4->next_fw_ev_idx =0 ; + } + +return IRQ_WAKE_THREAD ; +} + +static int qcusb4_usbap_rxterm_wa (struct qcom_usb4 *qcusb4) +{ +struct device *dev = qcusb4->nhi.dev; +u32 val; +int ret; + + val =readl (qcusb4->usb_cfg +USBAP_CFG_PHYSTATUS_EN ); +writel (val & ~PHYSTATUS_EN_EN , qcusb4->usb_cfg +USBAP_CFG_PHYSTATUS_EN ); + + val =readl (qcusb4->usb_cfg +USBAP_CFG_SYNC_RST_USB3 ); +writel (val |RST_USB3_RST , qcusb4->usb_cfg +USBAP_CFG_SYNC_RST_USB3 ); + + ret =reset_control_assert (qcusb4->usb_pipe_reset); +if (ret) +return dev_err_probe (dev, ret,"Couldn't assert usb_pipe reset\n" ); + +usleep_range (100 ,150 ); + + val =readl (qcusb4->usb_cfg +USBAP_CFG_PHYSTATUS_EN ); +writel (val |PHYSTATUS_EN_EN , qcusb4->usb_cfg +USBAP_CFG_PHYSTATUS_EN ); + + val =readl (qcusb4->cfg +CFG_SYS_CLK_CGC ); +writel (val & ~SYS_CLK_CGC_SYS_CLK_EN_USBAP , qcusb4->cfg +CFG_SYS_CLK_CGC ); + + ret =reset_control_deassert (qcusb4->usb_pipe_reset); +if (ret) +return dev_err_probe (dev, ret,"Couldn't deassert usb_pipe reset\n" ); + +usleep_range (100 ,150 ); + + val =readl (qcusb4->usb_cfg +USBAP_CFG_SYNC_RST_USB3 ); +writel (val & ~RST_USB3_RST , qcusb4->usb_cfg +USBAP_CFG_SYNC_RST_USB3 ); + + val =readl (qcusb4->usb_cfg +USBAP_CFG_RXTERM_BACKDOOR_CTRL ); +writel (val |RXTERM_RX_TERM , qcusb4->usb_cfg +USBAP_CFG_RXTERM_BACKDOOR_CTRL ); + +return qcusb4_fw_cmd (qcusb4,FW_CMD_WA_DONE ,WA_DONE_USBAP_RXTERM ); +} + +static irqreturn_t qcom_usb4_fw_irq_thread (int irq,void *data)
drivers/thunderbolt/qcom.c line 455
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+{ +struct qcom_usb4 *qcusb4 = data; +struct qcom_usb4_fw_events *fw_events = qcusb4->fw_events_buf; +struct device *dev = qcusb4->nhi.dev; +u32 entry_size = qcusb4->fw_ev_entry_size; +u16 num_new_entries, num_to_end; +void __iomem *entries; +u32 next_entry_index; + +if (!qcusb4->fw_ev_rb_base || !qcusb4->fw_ev_ring_size) {
How this can happen BTW?
drivers/thunderbolt/qcom.c line 462
Quoted 7 lines
drivers/thunderbolt/qcom.c new file +7
-0+qcom_usb4_fw_clear_irq (qcusb4); +return IRQ_HANDLED ; + } + +/* +* Clear before reading the write index. Otherwise an event written in between gets its IRQ +* cleared, but not read, and sits in the ring until something else fires the IRQ.
Wrap these too. Ditto everywhere.
drivers/thunderbolt/qcom.c line 467
Quoted 5 lines
drivers/thunderbolt/qcom.c new file +5
-0+*/ +qcom_usb4_fw_clear_irq (qcusb4); + + next_entry_index =readl (qcusb4->fw_ev_rb_base + + offsetof(struct qcom_usb4_fw_events , next_entry_index));
Would this read better if it is called "index"? Ditto for the other long names where it makes things more readable.
drivers/thunderbolt/qcom.c line 470
Quoted 3 lines
drivers/thunderbolt/qcom.c new file +3
-0+if (next_entry_index >= qcusb4->fw_ev_total_entry_num) { +dev_err_ratelimited (dev,"Invalid FW event index %u/%u\n" , + next_entry_index, qcusb4->fw_ev_total_entry_num);
Same question about the ratelimit here. Seems it is common to get invalid events from the FW?
Quoted 17 lines
drivers/thunderbolt/qcom.c new file +17
-0+return IRQ_HANDLED ; + } + +/* Check for ringbuffer rollover */ +if (next_entry_index < qcusb4->next_fw_ev_idx) + num_new_entries = qcusb4->fw_ev_total_entry_num - qcusb4->next_fw_ev_idx + + next_entry_index; +else + num_new_entries = next_entry_index - qcusb4->next_fw_ev_idx; + +/* Grab the header and the new entries (wrapping around) from the uC's RAM */ +memcpy_fromio (fw_events, qcusb4->fw_ev_rb_base,sizeof (*fw_events)); + entries = qcusb4->fw_ev_rb_base + offsetof(struct qcom_usb4_fw_events , entries); + num_to_end =min_t (u16, num_new_entries, + qcusb4->fw_ev_total_entry_num - qcusb4->next_fw_ev_idx); +memcpy_fromio ((void *)fw_events->entries + entry_size * qcusb4->next_fw_ev_idx, + entries + entry_size * qcusb4->next_fw_ev_idx, entry_size * num_to_end);
drivers/thunderbolt/qcom.c line 497
Quoted 10 lines
drivers/thunderbolt/qcom.c new file +10
-0+memcpy_fromio (fw_events->entries, entries, entry_size * (num_new_entries - num_to_end)); +/* Make sure we get the events before proceeding */ +mb (); + +if (le16_to_cpu (fw_events->num_unread_entries) >= qcusb4->fw_ev_total_entry_num) +dev_warn_ratelimited (dev,"FW event ring overflowed, events were lost\n" ); + +for (int i =0 ; i < num_new_entries; i++) { +struct qcom_usb4_fw_event *ev; +u16 payload_size = qcusb4->fw_ev_entry_size -sizeof (*ev);
Reverse-christmas tree where possible.
drivers/thunderbolt/qcom.c line 500
Quoted 3 lines
drivers/thunderbolt/qcom.c new file +3
-0+ + ev = (void *)fw_events->entries + + (qcusb4->fw_ev_entry_size * qcusb4->next_fw_ev_idx++);
This is hard to parse and easy to get wrong so perhaps split it to a couple of statements. Also check if you need the cast here.
drivers/thunderbolt/qcom.c line 513
Quoted 13 lines
drivers/thunderbolt/qcom.c new file +13
-0+ +switch (ev->opcode) { +case FW_MSG_MESSAGE : +dev_warn (qcusb4->nhi.dev,"FW MSG: %.*s\n" , payload_size, ev->params); +break ; +case FW_MSG_ERR : +if (payload_size <3 ) { +dev_err (dev,"Malformed FW error event\n" ); +break ; + } + +u8 error = ev->params[0 ]; +u16 extradata = (ev->params[2 ] <<8 ) | ev->params[1 ];
Please then make this a block with {
}
drivers/thunderbolt/qcom.c line 520
Quoted 7 lines
drivers/thunderbolt/qcom.c new file +7
-0+ +dev_err (qcusb4->nhi.dev,"Received FW error: %u (data: 0x%x)\n" , + error, extradata); +break ; +case FW_MSG_SLEEP_DONE : +complete (&qcusb4->sleep_acked); +dev_err (qcusb4->nhi.dev,"FW Sleep done\n" );
dev_err()?
drivers/thunderbolt/qcom.c line 523
Quoted 3 lines
drivers/thunderbolt/qcom.c new file +3
-0+break ; +case FW_MSG_EXIT_OFFLINE : +dev_err (qcusb4->nhi.dev,"FW exit offline\n" );
???
Okay I stoped here for now. As you say this is RFC so not yet production quality ;-) Thanks for posting, though. I now understand better the challenges "more OS control" poses. But we are getting there.. :)
RFC PATCH 14/15 arm64: dts: qcom: glymur: Add USB4 topology
In reply to Konrad DybcioDescribe the USB4 PHY clocks, router, Type-C endpoints, PCIe tunnel host interface, and tunneled DisplayPort resources on Glymur and the CRD.
Includes some work by Wesley Cheng.
--- arch/arm64/boot/dts/qcom/glymur-crd.dtsi | 29 +- arch/arm64/boot/dts/qcom/glymur.dtsi | 703 ++++++++++++++++++++++++++++++- 2 files changed, 724 insertions(+), 8 deletions(-)
arch/arm64/boot/dts/qcom/glymur-crd.dtsi +27 -2
@@ -87,13 +87,21 @@ pmic_glink_hs_in: endpoint { }; }; - port@1 { - reg = <1>; + port@2 { + reg = <2>; pmic_glink_ss_in: endpoint { remote-endpoint = <&usb_0_qmpphy_out>; }; }; + + port@1 { + reg = <1>; + + pmic_glink_usb4_in: endpoint { + remote-endpoint = <&usb4_0_mode_in>; + }; + }; }; };
@@ -122,6 +130,14 @@ pmic_glink_ss_in1: endpoint { remote-endpoint = <&usb_1_qmpphy_out>; }; }; + + port@2 { + reg = <2>; + + pmic_glink_usb4_in1: endpoint { + remote-endpoint = <&usb4_1_mode_in>; + }; + }; }; }; };
@@ -974,6 +990,7 @@ wwan_reg_en: wwan-reg-en-state { drive-strength = <2>; bias-disable; }; + }; &uart14 {
@@ -993,6 +1010,14 @@ bluetooth { }; }; +&usb4_0_mode_in { + remote-endpoint = <&pmic_glink_usb4_in>; +}; + +&usb4_1_mode_in { + remote-endpoint = <&pmic_glink_usb4_in1>; +}; + &usb_0 { status = "okay"; };
arch/arm64/boot/dts/qcom/glymur.dtsi +697 -6
760 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC PATCH 15/15 arm64: dts: qcom: glymur-crd: Enable the tertiary Type-C
In reply to Konrad DybcioThis is just for demonstration purposes for the series, a cleaner patch handling 2xType-C + HDMI variants will come separately.
--- arch/arm64/boot/dts/qcom/glymur-crd.dtsi | 82 ++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/qcom/glymur-crd.dtsi +78 -4
@@ -123,16 +123,16 @@ pmic_glink_hs_in1: endpoint { }; }; - port@1 { - reg = <1>; + port@2 { + reg = <2>; pmic_glink_ss_in1: endpoint { remote-endpoint = <&usb_1_qmpphy_out>; }; }; - port@2 { - reg = <2>; + port@1 { + reg = <1>; pmic_glink_usb4_in1: endpoint { remote-endpoint = <&usb4_1_mode_in>;
@@ -140,6 +140,42 @@ pmic_glink_usb4_in1: endpoint { }; }; }; + + connector@2 { + compatible = "usb-c-connector"; + reg = <2>; + power-role = "dual"; + data-role = "dual"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + pmic_glink_hs_in2: endpoint { + remote-endpoint = <&usb_2_dwc3_hs>; + }; + }; + + port@2 { + reg = <2>; + + pmic_glink_ss_in2: endpoint { + remote-endpoint = <&usb_2_qmpphy_out>; + }; + }; + + port@1 { + reg = <1>; + + pmic_glink_usb4_in2: endpoint { + remote-endpoint = <&usb4_2_mode_in>; + }; + }; + }; + }; }; vreg_edp_3p3: regulator-edp-3p3 {
@@ -563,6 +599,14 @@ &mdss_dp1_out { link-frequencies = /bits/ 64 <1620000000 2700000000 5400000000 8100000000>; }; +&mdss_dp2 { + status = "okay"; +}; + +&mdss_dp2_out { + link-frequencies = /bits/ 64 <1620000000 2700000000 5400000000 8100000000>; +}; + &mdss_dp3 { /delete-property/ #sound-dai-cells;
@@ -735,6 +779,10 @@ &remoteproc_cdsp { status = "okay"; }; +&smb2370_l_e2 { + status = "okay"; +}; + &sdhc_2 { vmmc-supply = <&vreg_l9b0>; vqmmc-supply = <&vreg_l2b0>;
@@ -1018,6 +1066,10 @@ &usb4_1_mode_in { remote-endpoint = <&pmic_glink_usb4_in1>; }; +&usb4_2_mode_in { + remote-endpoint = <&pmic_glink_usb4_in2>; +}; + &usb_0 { status = "okay"; };
@@ -1062,6 +1114,28 @@ &usb_1_qmpphy_out { remote-endpoint = <&pmic_glink_ss_in1>; }; +&usb_2 { + status = "okay"; +}; + +&usb_2_dwc3_hs { + remote-endpoint = <&pmic_glink_hs_in2>; +}; + +&usb_2_hsphy { + phys = <&smb2370_l_e2_eusb2_repeater>; + + status = "okay"; +}; + +&usb_2_qmpphy { + status = "okay"; +}; + +&usb_2_qmpphy_out { + remote-endpoint = <&pmic_glink_ss_in2>; +}; + &usb_hs { dr_mode = "host";
Signature · 1 line
2.55.0
Quoted 3 lines · Konrad Dybcio
Said state machine is an attempt to tame the delicate clock setup, which if we don't get perfectly right results in the machine hard- crashing. More on that in the big comment at the top of the driver.
Hi Konrad,
One data point on that from Hamoa, in case it is useful when the driver gets there.
On a Surface Laptop 7 15" (x1e80100-microsoft-romulus15) the SoC resets about 50 ms after the host router's USB3 adapter is enabled (2 of 2 runs, either port) unless the router's USB pipe clock has a vote:GCC_USB4_0_PHY_USB_PIPE_CLK (0x9f0a4) and GCC_USB4_1_PHY_USB_PIPE_CLK (0x2b0a4). With dwc3-qcom bound and awake their CLK_OFF bit is already clear while the enable bit is still 0, so the status alone looks fine. Voting for the clock before the USB3 path is enabled removes the reset on both ports.
This is on an out-of-tree stack (Jim Martin's Glymur driver extended to X1E80100), not on your series, so take it as a hardware observation only. USB3 and PCIe tunnels both run on that stack on this laptop.
[..]
Quoted 2 lines
It requires
loadable firmware which will be posted to linux-firmware soon.
Will that include the Hamoa router firmware, or Glymur only for now?
I can test on this laptop (two USB4 ports, PS8830 retimers) whenever a version of the series covers Hamoa, and report back.
One correction to my mail of 29 November [1]: the time I gave there for dock USB3 bring-up with the host retimer scan skipped (2.45 s to 0.96 s) did not reproduce when I measured again (1.36 s to 1.22 s). The drop counts in that mail stand.
[1] https://lore.kernel.org/all/[email protected]/
Thanks,
Felipe
Quoted 10 lines · Felipe Infante de Castro
Quoted 3 lines · Konrad Dybcio
Said state machine is an attempt to tame the delicate clock setup, which if we don't get perfectly right results in the machine hard- crashing. More on that in the big comment at the top of the driver.
Hi Konrad,
One data point on that from Hamoa, in case it is useful when the driver gets there.
Quoted 8 lines
On a Surface Laptop 7 15" (x1e80100-microsoft-romulus15) the SoC resets about 50 ms after the host router's USB3 adapter is enabled (2 of 2 runs, either port) unless the router's USB pipe clock has a vote:
GCC_USB4_0_PHY_USB_PIPE_CLK(0x9f0a4) andGCC_USB4_1_PHY_USB_PIPE_CLK(0x2b0a4). With dwc3-qcom bound and awake theirCLK_OFFbit is already clear while the enable bit is still 0, so the status alone looks fine. Voting for the clock before the USB3 path is enabled removes the reset on both ports.
Some clocks have hardware controls + the status reporting on pipe- derived clocks is sometimes hit and miss
Quoted 9 lines
This is on an out-of-tree stack (Jim Martin's Glymur driver extended to X1E80100), not on your series, so take it as a hardware observation only. USB3 and PCIe tunnels both run on that stack on this laptop.
[..]
Quoted 2 lines
It requires
loadable firmware which will be posted to linux-firmware soon.Will that include the Hamoa router firmware, or Glymur only for now?
Both are now merged in linux-firmware.
Quoted 2 lines
I can test on this laptop (two USB4 ports, PS8830 retimers) whenever a version of the series covers Hamoa, and report back.
I have the exact same laptop at hand, but I'll gladly accept your testing when that's ready!
Konrad
Quoted 25 lines · Konrad Dybcio
Quoted 9 lines · Felipe Infante de Castro
Quoted 3 lines · Konrad Dybcio
Said state machine is an attempt to tame the delicate clock setup, which if we don't get perfectly right results in the machine hard- crashing. More on that in the big comment at the top of the driver.
Hi Konrad,
One data point on that from Hamoa, in case it is useful when the driver gets there.
Quoted 8 lines
On a Surface Laptop 7 15" (x1e80100-microsoft-romulus15) the SoC resets about 50 ms after the host router's USB3 adapter is enabled (2 of 2 runs, either port) unless the router's USB pipe clock has a vote:
GCC_USB4_0_PHY_USB_PIPE_CLK(0x9f0a4) andGCC_USB4_1_PHY_USB_PIPE_CLK(0x2b0a4). With dwc3-qcom bound and awake theirCLK_OFFbit is already clear while the enable bit is still 0, so the status alone looks fine. Voting for the clock before the USB3 path is enabled removes the reset on both ports.Some clocks have hardware controls + the status reporting on pipe- derived clocks is sometimes hit and miss
Quoted 4 lines
This is on an out-of-tree stack (Jim Martin's Glymur driver extended to X1E80100), not on your series, so take it as a hardware observation only. USB3 and PCIe tunnels both run on that stack on this laptop.
Quoted 5 lines
Quoted 4 lines
[..]
Quoted 2 lines
It requires
loadable firmware which will be posted to linux-firmware soon.Will that include the Hamoa router firmware, or Glymur only for now?
Both are now merged in linux-firmware.
Yay!
Quoted 4 lines
Quoted 2 lines
I can test on this laptop (two USB4 ports, PS8830 retimers) whenever a version of the series covers Hamoa, and report back.
I have the exact same laptop at hand, but I'll gladly accept your testing when that's ready!
FWIW, I've been testing the unholy combination of this series + my own hamoa dts definitions + temporary PCIe RC driver from the early unofficial slop attempts + my modifications to this series to manage that thing's lifecycle:
https://github.com/valpackett/linux-qclaptops/commits/uwu-next/
AMDGPU works great, even hot unplug of it :) I do see a bit of AER correctables but they don't seem to impact performance much at all.
Did NOT need to mess with USB3 clocks or anything. I think that's just because of the actual *USB4* part of the slopinated attempts was absolutely horrendous, confusing Glymur/Hamoa differences with cold/hot boot ones, etc. (I needed to unslop the PCIe part a lil bit too, heh.) This RFC series seems to handle everything very well.
Thanks,
~val