diff --git a/drivers/thunderbolt/apple-dpin-state.c b/drivers/thunderbolt/apple-dpin-state.c index afaa64e3f6ba6..3ab66222ff72f 100644 --- a/drivers/thunderbolt/apple-dpin-state.c +++ b/drivers/thunderbolt/apple-dpin-state.c @@ -58,7 +58,8 @@ const struct apple_dpin_policy apple_dpin_m4 = { * DP IN handshake writes only DPTX_INACTIVE (+0x0c bit 0) and polls its ACK * (+0x10 bit 0), gated on HPD. A tunnel whose DP IN block DCP never * activated is torn down without the inactive handshake. A DPRX that is not - * done in time keeps the tunnel: the display may still train. + * done in time keeps the tunnel: the display may still train. Bandwidth + * allocation runs as on macOS (TB_HOST_DP_BW_HELD_ACK). */ const struct apple_dpin_policy apple_dpin_m5 = { .flow = APPLE_DPIN_CHANGED, @@ -66,7 +67,8 @@ const struct apple_dpin_policy apple_dpin_m5 = { .capacity_retry = true, .setup_irqs = true, .defer_new_bringup = true, - .host_policy = TB_HOST_DP_NOTIFY | TB_HOST_DP_KEEP_DPRX_TIMEOUT, + .host_policy = TB_HOST_DP_NOTIFY | TB_HOST_DP_KEEP_DPRX_TIMEOUT | + TB_HOST_DP_BW_HELD_ACK, .lazy_idle = true, }; diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h index 6a7461ed5602e..1ef928273851a 100644 --- a/drivers/thunderbolt/nhi.h +++ b/drivers/thunderbolt/nhi.h @@ -255,6 +255,13 @@ struct tb_nhi_ops { * being set up again at HBR2 first. */ #define TB_HOST_DP_SHARED_RATE BIT(6) +/* + * Run the host DP IN adapters' bandwidth allocation mode as the host's own + * OS does: 1 Gb/s granularity, and the connection manager acknowledges a + * DPTX bandwidth request by holding CM Ack until the adapter has cleared + * the request. + */ +#define TB_HOST_DP_BW_HELD_ACK BIT(7) /* * Minimal number of vectors when we use MSI-X. Two for control channel diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index 09556c4b7048e..68fe9fa0b51dd 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -1173,6 +1173,13 @@ static inline bool tb_port_is_apple_host_dpin(const struct tb_port *port) bool tb_has_apple_host_dp_tunnel(struct tb *tb); +/* Host DP IN adapter whose bandwidth allocation runs as TB_HOST_DP_BW_HELD_ACK says. */ +static inline bool tb_port_dp_bw_held_ack(const struct tb_port *port) +{ + return tb_port_is_apple_host_dpin(port) && + (port->sw->tb->nhi->host_dp_policy & TB_HOST_DP_BW_HELD_ACK); +} + static inline bool tb_port_needs_host_dp_credits(const struct tb_port *port) { const struct tb *tb = port->sw->tb; diff --git a/drivers/thunderbolt/tunnel.c b/drivers/thunderbolt/tunnel.c index f3ddd34191f0c..22c707a643c1d 100644 --- a/drivers/thunderbolt/tunnel.c +++ b/drivers/thunderbolt/tunnel.c @@ -1258,6 +1258,9 @@ static int tb_dp_bandwidth_alloc_mode_enable(struct tb_tunnel *tunnel) for (granularity = 250; tmp / granularity > 255 && granularity <= 1000; granularity *= 2) ; + /* The host's own OS programs these adapters at 1 Gb/s. */ + if (tb_port_dp_bw_held_ack(in)) + granularity = 1000; tb_tunnel_dbg(tunnel, "granularity %d Mb/s\n", granularity); diff --git a/drivers/thunderbolt/usb4.c b/drivers/thunderbolt/usb4.c index dc5dc17498b86..8070157910792 100644 --- a/drivers/thunderbolt/usb4.c +++ b/drivers/thunderbolt/usb4.c @@ -3009,23 +3009,30 @@ static inline int usb4_dp_port_set_cm_ack(struct tb_port *port) return __usb4_dp_port_set_cm_ack(port, true); } +/* + * With @held the CM Ack just set stays set until the adapter has cleared + * the DPTX request, as the Apple silicon host's own OS acknowledges it; + * otherwise it is cleared at once, before waiting. + */ static int usb4_dp_port_wait_and_clear_cm_ack(struct tb_port *port, - int timeout_msec) + int timeout_msec, bool held) { ktime_t end; u32 val; int ret; - ret = __usb4_dp_port_set_cm_ack(port, false); - if (ret) - return ret; + if (!held) { + ret = __usb4_dp_port_set_cm_ack(port, false); + if (ret) + return ret; + } end = ktime_add_ms(ktime_get(), timeout_msec); do { ret = tb_port_read(port, &val, TB_CFG_PORT, port->cap_adap + ADP_DP_CS_8, 1); if (ret) - return ret; + goto err_held; if (!(val & ADP_DP_CS_8_DR)) break; @@ -3035,7 +3042,8 @@ static int usb4_dp_port_wait_and_clear_cm_ack(struct tb_port *port, if (val & ADP_DP_CS_8_DR) { tb_port_warn(port, "timeout waiting for DPTX request to clear\n"); - return -ETIMEDOUT; + ret = -ETIMEDOUT; + goto err_held; } ret = tb_port_read(port, &val, TB_CFG_PORT, @@ -3046,6 +3054,12 @@ static int usb4_dp_port_wait_and_clear_cm_ack(struct tb_port *port, val &= ~ADP_DP_CS_2_CA; return tb_port_write(port, &val, TB_CFG_PORT, port->cap_adap + ADP_DP_CS_2, 1); + +err_held: + /* A held CM Ack is not left set when the request does not clear. */ + if (held) + __usb4_dp_port_set_cm_ack(port, false); + return ret; } /** @@ -3088,7 +3102,8 @@ int usb4_dp_port_allocate_bandwidth(struct tb_port *port, int bw) if (ret) return ret; - return usb4_dp_port_wait_and_clear_cm_ack(port, 500); + return usb4_dp_port_wait_and_clear_cm_ack(port, 500, + tb_port_dp_bw_held_ack(port)); } /**