Skip to content
Merged
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
6 changes: 4 additions & 2 deletions drivers/thunderbolt/apple-dpin-state.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ 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,
.settle_ms = 100,
.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,
};

Expand Down
7 changes: 7 additions & 0 deletions drivers/thunderbolt/nhi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions drivers/thunderbolt/tb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions drivers/thunderbolt/tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
29 changes: 22 additions & 7 deletions drivers/thunderbolt/usb4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand Down
Loading