Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thunderbolt: Enable TMU access when accessing port space on legacy devices

Light Ridge and Eagle Ridge both need to have TMU access enabled before
port space can be fully accessed so make sure it happens on those. This
allows us to get rid of the offset quirk in tb_port_find_cap().

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>

+62 -17
+52 -17
drivers/thunderbolt/cap.c
··· 13 13 14 14 #define CAP_OFFSET_MAX 0xff 15 15 #define VSE_CAP_OFFSET_MAX 0xffff 16 + #define TMU_ACCESS_EN BIT(20) 16 17 17 18 struct tb_cap_any { 18 19 union { ··· 23 22 }; 24 23 } __packed; 25 24 26 - /** 27 - * tb_port_find_cap() - Find port capability 28 - * @port: Port to find the capability for 29 - * @cap: Capability to look 30 - * 31 - * Returns offset to start of capability or %-ENOENT if no such 32 - * capability was found. Negative errno is returned if there was an 33 - * error. 34 - */ 35 - int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap) 25 + static int tb_port_enable_tmu(struct tb_port *port, bool enable) 36 26 { 37 - u32 offset; 27 + struct tb_switch *sw = port->sw; 28 + u32 value, offset; 29 + int ret; 38 30 39 31 /* 40 - * DP out adapters claim to implement TMU capability but in 41 - * reality they do not so we hard code the adapter specific 42 - * capability offset here. 32 + * Legacy devices need to have TMU access enabled before port 33 + * space can be fully accessed. 43 34 */ 44 - if (port->config.type == TB_TYPE_DP_HDMI_OUT) 45 - offset = 0x39; 35 + if (tb_switch_is_lr(sw)) 36 + offset = 0x26; 37 + else if (tb_switch_is_er(sw)) 38 + offset = 0x2a; 46 39 else 47 - offset = 0x1; 40 + return 0; 41 + 42 + ret = tb_sw_read(sw, &value, TB_CFG_SWITCH, offset, 1); 43 + if (ret) 44 + return ret; 45 + 46 + if (enable) 47 + value |= TMU_ACCESS_EN; 48 + else 49 + value &= ~TMU_ACCESS_EN; 50 + 51 + return tb_sw_write(sw, &value, TB_CFG_SWITCH, offset, 1); 52 + } 53 + 54 + static int __tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap) 55 + { 56 + u32 offset = 1; 48 57 49 58 do { 50 59 struct tb_cap_any header; ··· 71 60 } while (offset); 72 61 73 62 return -ENOENT; 63 + } 64 + 65 + /** 66 + * tb_port_find_cap() - Find port capability 67 + * @port: Port to find the capability for 68 + * @cap: Capability to look 69 + * 70 + * Returns offset to start of capability or %-ENOENT if no such 71 + * capability was found. Negative errno is returned if there was an 72 + * error. 73 + */ 74 + int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap) 75 + { 76 + int ret; 77 + 78 + ret = tb_port_enable_tmu(port, true); 79 + if (ret) 80 + return ret; 81 + 82 + ret = __tb_port_find_cap(port, cap); 83 + 84 + tb_port_enable_tmu(port, false); 85 + 86 + return ret; 74 87 } 75 88 76 89 static int tb_switch_find_cap(struct tb_switch *sw, enum tb_switch_cap cap)
+10
drivers/thunderbolt/tb.h
··· 436 436 return NULL; 437 437 } 438 438 439 + static inline bool tb_switch_is_lr(const struct tb_switch *sw) 440 + { 441 + return sw->config.device_id == PCI_DEVICE_ID_INTEL_LIGHT_RIDGE; 442 + } 443 + 444 + static inline bool tb_switch_is_er(const struct tb_switch *sw) 445 + { 446 + return sw->config.device_id == PCI_DEVICE_ID_INTEL_EAGLE_RIDGE; 447 + } 448 + 439 449 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged); 440 450 int tb_port_add_nfc_credits(struct tb_port *port, int credits); 441 451 int tb_port_clear_counter(struct tb_port *port, int counter);