Commit 343fcb8c authored by Andreas Noever's avatar Andreas Noever Committed by Greg Kroah-Hartman

thunderbolt: Fix nontrivial endpoint devices.

Fix issues observed with the Startech docking station:

Fix the type of the route parameter in tb_ctl_rx. It should be u64 and not
u8 (which only worked for short routes).

A thunderbolt cable contains two lanes. If both endpoints support it a
connection will be established on both lanes. Previously we tried to
scan below both "dual link ports". Use the information extracted from
the drom to only scan behind ports with lane_nr == 0.

Endpoints with more complex thunderbolt controllers have some of their
ports disabled (for example the NHI port or one of the HDMI/DP ports).
Accessing them results in an error so we now ignore ports which are
marked as disabled in the drom.
Signed-off-by: default avatarAndreas Noever <andreas.noever@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cd22e73b
...@@ -439,7 +439,7 @@ static void tb_ctl_rx_callback(struct tb_ring *ring, struct ring_frame *frame, ...@@ -439,7 +439,7 @@ static void tb_ctl_rx_callback(struct tb_ring *ring, struct ring_frame *frame,
*/ */
static struct tb_cfg_result tb_ctl_rx(struct tb_ctl *ctl, void *buffer, static struct tb_cfg_result tb_ctl_rx(struct tb_ctl *ctl, void *buffer,
size_t length, int timeout_msec, size_t length, int timeout_msec,
u8 route, enum tb_cfg_pkg_type type) u64 route, enum tb_cfg_pkg_type type)
{ {
struct tb_cfg_result res; struct tb_cfg_result res;
struct ctl_pkg *pkg; struct ctl_pkg *pkg;
......
...@@ -180,20 +180,17 @@ int tb_port_clear_counter(struct tb_port *port, int counter) ...@@ -180,20 +180,17 @@ int tb_port_clear_counter(struct tb_port *port, int counter)
* *
* Return: Returns 0 on success or an error code on failure. * Return: Returns 0 on success or an error code on failure.
*/ */
static int tb_init_port(struct tb_switch *sw, u8 port_nr) static int tb_init_port(struct tb_port *port)
{ {
int res; int res;
int cap; int cap;
struct tb_port *port = &sw->ports[port_nr];
port->sw = sw;
port->port = port_nr;
port->remote = NULL;
res = tb_port_read(port, &port->config, TB_CFG_PORT, 0, 8); res = tb_port_read(port, &port->config, TB_CFG_PORT, 0, 8);
if (res) if (res)
return res; return res;
/* Port 0 is the switch itself and has no PHY. */ /* Port 0 is the switch itself and has no PHY. */
if (port->config.type == TB_TYPE_PORT && port_nr != 0) { if (port->config.type == TB_TYPE_PORT && port->port != 0) {
cap = tb_find_cap(port, TB_CFG_PORT, TB_CAP_PHY); cap = tb_find_cap(port, TB_CFG_PORT, TB_CAP_PHY);
if (cap > 0) if (cap > 0)
...@@ -202,7 +199,7 @@ static int tb_init_port(struct tb_switch *sw, u8 port_nr) ...@@ -202,7 +199,7 @@ static int tb_init_port(struct tb_switch *sw, u8 port_nr)
tb_port_WARN(port, "non switch port without a PHY\n"); tb_port_WARN(port, "non switch port without a PHY\n");
} }
tb_dump_port(sw->tb, &port->config); tb_dump_port(port->sw->tb, &port->config);
/* TODO: Read dual link port, DP port and more from EEPROM. */ /* TODO: Read dual link port, DP port and more from EEPROM. */
return 0; return 0;
...@@ -329,6 +326,7 @@ void tb_switch_free(struct tb_switch *sw) ...@@ -329,6 +326,7 @@ void tb_switch_free(struct tb_switch *sw)
tb_plug_events_active(sw, false); tb_plug_events_active(sw, false);
kfree(sw->ports); kfree(sw->ports);
kfree(sw->drom);
kfree(sw); kfree(sw);
} }
...@@ -386,13 +384,11 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, u64 route) ...@@ -386,13 +384,11 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, u64 route)
goto err; goto err;
for (i = 0; i <= sw->config.max_port_number; i++) { for (i = 0; i <= sw->config.max_port_number; i++) {
if (tb_init_port(sw, i)) /* minimum setup for tb_find_cap and tb_drom_read to work */
goto err; sw->ports[i].sw = sw;
/* TODO: check if port is disabled (EEPROM) */ sw->ports[i].port = i;
} }
/* TODO: I2C, IECS, EEPROM, link controller */
cap = tb_find_cap(&sw->ports[0], TB_CFG_SWITCH, TB_CAP_PLUG_EVENTS); cap = tb_find_cap(&sw->ports[0], TB_CFG_SWITCH, TB_CAP_PLUG_EVENTS);
if (cap < 0) { if (cap < 0) {
tb_sw_warn(sw, "cannot find TB_CAP_PLUG_EVENTS aborting\n"); tb_sw_warn(sw, "cannot find TB_CAP_PLUG_EVENTS aborting\n");
...@@ -400,17 +396,29 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, u64 route) ...@@ -400,17 +396,29 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, u64 route)
} }
sw->cap_plug_events = cap; sw->cap_plug_events = cap;
if (tb_drom_read_uid_only(sw, &sw->uid)) /* read drom */
tb_sw_warn(sw, "could not read uid from eeprom\n"); if (tb_drom_read(sw))
else tb_sw_warn(sw, "tb_eeprom_read_rom failed, continuing\n");
tb_sw_info(sw, "uid: %#llx\n", sw->uid); tb_sw_info(sw, "uid: %#llx\n", sw->uid);
for (i = 0; i <= sw->config.max_port_number; i++) {
if (sw->ports[i].disabled) {
tb_port_info(&sw->ports[i], "disabled by eeprom\n");
continue;
}
if (tb_init_port(&sw->ports[i]))
goto err;
}
/* TODO: I2C, IECS, link controller */
if (tb_plug_events_active(sw, true)) if (tb_plug_events_active(sw, true))
goto err; goto err;
return sw; return sw;
err: err:
kfree(sw->ports); kfree(sw->ports);
kfree(sw->drom);
kfree(sw); kfree(sw);
return NULL; return NULL;
} }
......
...@@ -38,6 +38,11 @@ static void tb_scan_port(struct tb_port *port) ...@@ -38,6 +38,11 @@ static void tb_scan_port(struct tb_port *port)
return; return;
if (port->config.type != TB_TYPE_PORT) if (port->config.type != TB_TYPE_PORT)
return; return;
if (port->dual_link_port && port->link_nr)
return; /*
* Downstream switch is reachable through two ports.
* Only scan on the primary port (link_nr == 0).
*/
if (tb_wait_for_port(port, false) <= 0) if (tb_wait_for_port(port, false) <= 0)
return; return;
if (port->remote) { if (port->remote) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment