summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Westerberg <mika.westerberg@linux.intel.com>2017-10-12 09:45:50 -0400
committerMika Westerberg <mika.westerberg@linux.intel.com>2019-04-18 04:18:53 -0400
commite78db6f08b6a2a50eea9ed4146f019026491d63c (patch)
tree149d4dd58b84d74859d8721cb21fe9ba939656a5
parent344e06430a72347b554a7fd98f3a961084f37be6 (diff)
thunderbolt: Generalize port finding routines to support all port types
We will be needing these routines to find Display Port adapters as well so modify them to take port type as the second parameter. Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
-rw-r--r--drivers/thunderbolt/switch.c16
-rw-r--r--drivers/thunderbolt/tb.c35
-rw-r--r--drivers/thunderbolt/tb.h1
3 files changed, 34 insertions, 18 deletions
diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index 00aec2124f79..028e9a293382 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -731,6 +731,22 @@ struct tb_port *tb_next_port_on_path(struct tb_port *start, struct tb_port *end,
731} 731}
732 732
733/** 733/**
734 * tb_port_is_enabled() - Is the adapter port enabled
735 * @port: Port to check
736 */
737bool tb_port_is_enabled(struct tb_port *port)
738{
739 switch (port->config.type) {
740 case TB_TYPE_PCIE_UP:
741 case TB_TYPE_PCIE_DOWN:
742 return tb_pci_port_is_enabled(port);
743
744 default:
745 return false;
746 }
747}
748
749/**
734 * tb_pci_port_is_enabled() - Is the PCIe adapter port enabled 750 * tb_pci_port_is_enabled() - Is the PCIe adapter port enabled
735 * @port: PCIe port to check 751 * @port: PCIe port to check
736 */ 752 */
diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index fb01396a62a9..903922a16d64 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -180,40 +180,39 @@ static void tb_free_unplugged_children(struct tb_switch *sw)
180 } 180 }
181} 181}
182 182
183
184/** 183/**
185 * find_pci_up_port() - return the first PCIe up port on @sw or NULL 184 * tb_find_port() - return the first port of @type on @sw or NULL
185 * @sw: Switch to find the port from
186 * @type: Port type to look for
186 */ 187 */
187static struct tb_port *tb_find_pci_up_port(struct tb_switch *sw) 188static struct tb_port *tb_find_port(struct tb_switch *sw,
189 enum tb_port_type type)
188{ 190{
189 int i; 191 int i;
190 for (i = 1; i <= sw->config.max_port_number; i++) 192 for (i = 1; i <= sw->config.max_port_number; i++)
191 if (sw->ports[i].config.type == TB_TYPE_PCIE_UP) 193 if (sw->ports[i].config.type == type)
192 return &sw->ports[i]; 194 return &sw->ports[i];
193 return NULL; 195 return NULL;
194} 196}
195 197
196/** 198/**
197 * find_unused_down_port() - return the first inactive PCIe down port on @sw 199 * tb_find_unused_port() - return the first inactive port on @sw
200 * @sw: Switch to find the port on
201 * @type: Port type to look for
198 */ 202 */
199static struct tb_port *tb_find_unused_down_port(struct tb_switch *sw) 203static struct tb_port *tb_find_unused_port(struct tb_switch *sw,
204 enum tb_port_type type)
200{ 205{
201 int i; 206 int i;
202 int cap; 207
203 int res;
204 int data;
205 for (i = 1; i <= sw->config.max_port_number; i++) { 208 for (i = 1; i <= sw->config.max_port_number; i++) {
206 if (tb_is_upstream_port(&sw->ports[i])) 209 if (tb_is_upstream_port(&sw->ports[i]))
207 continue; 210 continue;
208 if (sw->ports[i].config.type != TB_TYPE_PCIE_DOWN) 211 if (sw->ports[i].config.type != type)
209 continue;
210 cap = sw->ports[i].cap_adap;
211 if (!cap)
212 continue; 212 continue;
213 res = tb_port_read(&sw->ports[i], &data, TB_CFG_PORT, cap, 1); 213 if (!sw->ports[i].cap_adap)
214 if (res < 0)
215 continue; 214 continue;
216 if (data & 0x80000000) 215 if (tb_port_is_enabled(&sw->ports[i]))
217 continue; 216 continue;
218 return &sw->ports[i]; 217 return &sw->ports[i];
219 } 218 }
@@ -255,7 +254,7 @@ static struct tb_port *tb_find_pcie_down(struct tb_switch *sw,
255 } 254 }
256 255
257out: 256out:
258 return tb_find_unused_down_port(sw); 257 return tb_find_unused_port(sw, TB_TYPE_PCIE_DOWN);
259} 258}
260 259
261static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw) 260static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)
@@ -265,7 +264,7 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)
265 struct tb_switch *parent_sw; 264 struct tb_switch *parent_sw;
266 struct tb_tunnel *tunnel; 265 struct tb_tunnel *tunnel;
267 266
268 up = tb_find_pci_up_port(sw); 267 up = tb_find_port(sw, TB_TYPE_PCIE_UP);
269 if (!up) 268 if (!up)
270 return 0; 269 return 0;
271 270
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
index 260360ec59a9..e6040c9f68fa 100644
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -576,6 +576,7 @@ struct tb_port *tb_next_port_on_path(struct tb_port *start, struct tb_port *end,
576 576
577int tb_switch_find_vse_cap(struct tb_switch *sw, enum tb_switch_vse_cap vsec); 577int tb_switch_find_vse_cap(struct tb_switch *sw, enum tb_switch_vse_cap vsec);
578int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap); 578int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap);
579bool tb_port_is_enabled(struct tb_port *port);
579 580
580bool tb_pci_port_is_enabled(struct tb_port *port); 581bool tb_pci_port_is_enabled(struct tb_port *port);
581int tb_pci_port_enable(struct tb_port *port, bool enable); 582int tb_pci_port_enable(struct tb_port *port, bool enable);