Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions drivers/thunderbolt/apple-cio-sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static int apple_nhi_cio_router_wake(struct tb_nhi *nhi)
struct apple_nhi *anhi = nhi_to_anhi(nhi);
struct tb_switch *sw = anhi->tb->root_switch;
struct tb_port *port;
u32 cable_info;
int cap, ret;

cap = tb_switch_find_vse_cap(sw, TB_VSE_CAP_APPLE);
Expand All @@ -60,10 +61,10 @@ static int apple_nhi_cio_router_wake(struct tb_nhi *nhi)
if (ret)
dev_warn(anhi->dev, "CIO port %u unlock failed: %d\n", port->port, ret);
}
ret = tb_sw_write(sw, &anhi->acio->current_cable_info, TB_CFG_SWITCH,
cable_info = apple_nhi_cable_info(anhi, anhi->acio->current_cable_info);
ret = tb_sw_write(sw, &cable_info, TB_CFG_SWITCH,
cap + TB_VSE_CAP_APPLE_CABLE_INFO, 1);
dev_info(anhi->dev, "CIO cable word %#x written: %d\n", anhi->acio->current_cable_info,
ret);
dev_info(anhi->dev, "CIO cable word %#x written: %d\n", cable_info, ret);
return ret;
}

Expand Down Expand Up @@ -285,17 +286,18 @@ static int apple_nhi_cio_router_wake_t6050(struct tb_nhi *nhi)
{
struct apple_nhi *anhi = nhi_to_anhi(nhi);
struct tb_switch *sw = anhi->tb->root_switch;
u32 cable_info;
int cap, ret;

apple_nhi_cio_wake_op_t6050(anhi, APPLE_CIO_T6050_WAKE_OP_A, 0);
apple_nhi_cio_wake_op_t6050(anhi, APPLE_CIO_T6050_WAKE_OP_B, APPLE_CIO_T6050_WAKE_OP_B_META);
cap = tb_switch_find_vse_cap(sw, TB_VSE_CAP_APPLE);
if (cap < 0)
return cap;
ret = tb_sw_write(sw, &anhi->acio->current_cable_info, TB_CFG_SWITCH,
cable_info = apple_nhi_cable_info(anhi, anhi->acio->current_cable_info);
ret = tb_sw_write(sw, &cable_info, TB_CFG_SWITCH,
cap + TB_VSE_CAP_APPLE_CABLE_INFO, 1);
dev_info(anhi->dev, "CIO cable word %#x written: %d\n", anhi->acio->current_cable_info,
ret);
dev_info(anhi->dev, "CIO cable word %#x written: %d\n", cable_info, ret);
return ret;
}

Expand Down
72 changes: 59 additions & 13 deletions drivers/thunderbolt/apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ struct apple_cio_hw {
bool run_store;
/* Hold LSTX low as a GPIO from probe until the router first takes it. */
bool lstx_hold_from_probe;
/* The router trains Gen4 only on a cable word that says Gen4. */
bool gen4_cable;
/* Run Gen4 links with link recovery enabled at both ends. */
bool gen4_link_recovery;
/* Leave the host router's TMU to its firmware; host TMU constants. */
bool host_tmu;
const struct apple_dpin_policy *dp;
Expand Down Expand Up @@ -220,6 +216,8 @@ static const struct apple_cio_hw apple_cio_t8142_hw = {
* the M5 policy, see apple_dpin_m5. A Gen4 link times out CL training once CL
* states are enabled, then drops; it also dropped in the middle of a
* transition to an asymmetric width. Its links stay in CL0 and symmetric.
* Gen4 itself is not a property of this description: see
* apple_nhi_host_gen4().
*/
static const struct apple_cio_hw apple_cio_t6050_hw = {
.dpin_count = 4,
Expand All @@ -229,10 +227,8 @@ static const struct apple_cio_hw apple_cio_t6050_hw = {
.lstx_after_boot = true,
.lstx_hold_from_probe = true,
.strict_fw_ready = true,
.gen4_cable = true,
.no_host_clx = true,
.no_asym = true,
.gen4_link_recovery = true,
.host_tmu = true,
.dp = &apple_dpin_m5,
};
Expand Down Expand Up @@ -2578,6 +2574,47 @@ static const struct tb_nhi_ring_layout apple_nhi_ring_layout = {
.options_stride = APPLE_CIO_NHI_RING_STRIDE,
};

/*
* A host router that can run USB4 Gen4 says so in the Supported Link Speeds
* field of its lane adapters (USB4 v2, LANE_ADP_CS_0). The field is the
* same on every Apple USB4 router, so this, not the SoC, decides whether a
* Gen4 cable word is handed to the router.
*/
static bool apple_nhi_host_gen4(struct tb_switch *sw)
{
struct tb_port *port;
u32 val;

tb_switch_for_each_port(sw, port) {
if (!tb_port_is_null(port) || !port->cap_phy)
continue;
if (tb_port_read(port, &val, TB_CFG_PORT,
port->cap_phy + LANE_ADP_CS_0, 1))
continue;
if (FIELD_GET(LANE_ADP_CS_0_SUPPORTED_SPEED_MASK, val) &
LANE_ADP_CS_0_SUPPORTED_SPEED_GEN4)
return true;
}
return false;
}

/*
* The cable word as the host router gets it: a Gen4 cable on a router
* without Gen4 is a 20 Gb/s cable to it.
*/
static u32 apple_nhi_cable_info(struct apple_nhi *anhi, u32 info)
{
if (!(info & TB_VSE_CAP_APPLE_CABLE_INFO_GEN4))
return info;
if (apple_nhi_host_gen4(anhi->tb->root_switch)) {
dev_dbg(anhi->dev, "Gen4 cable, host router supports Gen4\n");
return info;
}
dev_dbg(anhi->dev, "Gen4 cable, host router is Gen3: 20 Gb/s cable word\n");
return (info & ~TB_VSE_CAP_APPLE_CABLE_INFO_GEN4) |
TB_VSE_CAP_APPLE_CABLE_INFO_20_GBPS;
}

static int apple_nhi_probe(struct platform_device *pdev)
{
struct apple_cio *acio = dev_get_drvdata(pdev->dev.parent);
Expand All @@ -2586,6 +2623,7 @@ static int apple_nhi_probe(struct platform_device *pdev)
struct resource *res;
struct tb_port *port;
enum apple_dpin_flow dp_hooks;
u32 cable_info;
int cap_apple;
int ret = 0;

Expand Down Expand Up @@ -2702,8 +2740,13 @@ static int apple_nhi_probe(struct platform_device *pdev)
anhi->nhi.quirks |= QUIRK_NO_HOST_CLX;
if (acio->hw->no_asym)
anhi->nhi.quirks |= QUIRK_NO_ASYM;
if (acio->hw->gen4_link_recovery)
anhi->nhi.quirks |= QUIRK_GEN4_LINK_RECOVERY;
/*
* The router firmware has no way back from a Gen4 link error but to
* disconnect the link unless link recovery is on at both ends. The core
* only touches links that trained at Gen4, so this is a no-op on routers
* and cables without Gen4.
*/
anhi->nhi.quirks |= QUIRK_GEN4_LINK_RECOVERY;
if (acio->hw->host_tmu)
anhi->nhi.quirks |= QUIRK_HOST_TMU;

Expand Down Expand Up @@ -2791,7 +2834,8 @@ static int apple_nhi_probe(struct platform_device *pdev)
port->port, ret);
}

ret = tb_sw_write(anhi->tb->root_switch, &acio->target_cable_info, TB_CFG_SWITCH,
cable_info = apple_nhi_cable_info(anhi, acio->target_cable_info);
ret = tb_sw_write(anhi->tb->root_switch, &cable_info, TB_CFG_SWITCH,
cap_apple + TB_VSE_CAP_APPLE_CABLE_INFO, 1);
if (ret) {
dev_warn(anhi->dev, "Setting VSE Apple cable info failed: %d\n", ret);
Expand Down Expand Up @@ -3900,11 +3944,13 @@ static int apple_cio_tbt_switch_set(struct typec_thunderbolt_switch_dev *sw,
if (FIELD_GET(EUDO_CABLE_TYPE_MASK, data->usb4.eudo) != EUDO_CABLE_TYPE_PASSIVE)
acio->target_cable_info |= TB_VSE_CAP_APPLE_CABLE_INFO_ACTIVE_CABLE;
/*
* The T6050 router firmware trains Gen4 only on a Gen4 cable, and
* takes Gen4 alone: no 20 Gb/s bit beside it.
* The router firmware trains Gen4 only on a Gen4 cable, and takes
* Gen4 alone: no 20 Gb/s bit beside it. Whether the host router
* can run Gen4 at all is only known once its config space is up:
* apple_nhi_cable_info() turns this into the 20 Gb/s word there
* for a router without Gen4.
*/
if (acio->hw->gen4_cable &&
FIELD_GET(EUDO_CABLE_SPEED_MASK, data->usb4.eudo) >=
if (FIELD_GET(EUDO_CABLE_SPEED_MASK, data->usb4.eudo) >=
APPLE_EUDO_CABLE_SPEED_USB4_GEN4)
acio->target_cable_info |= TB_VSE_CAP_APPLE_CABLE_INFO_GEN4;
else if (FIELD_GET(EUDO_CABLE_SPEED_MASK, data->usb4.eudo) >=
Expand Down
1 change: 1 addition & 0 deletions drivers/thunderbolt/tb_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ struct tb_regs_port_header {
#define LANE_ADP_CS_0 0x00
#define LANE_ADP_CS_0_SUPPORTED_SPEED_MASK GENMASK(19, 16)
#define LANE_ADP_CS_0_SUPPORTED_SPEED_SHIFT 16
#define LANE_ADP_CS_0_SUPPORTED_SPEED_GEN4 0x2
#define LANE_ADP_CS_0_SUPPORTED_WIDTH_MASK GENMASK(25, 20)
#define LANE_ADP_CS_0_SUPPORTED_WIDTH_SHIFT 20
#define LANE_ADP_CS_0_SUPPORTED_WIDTH_DUAL 0x2
Expand Down
Loading