Commit 93f36ade authored by Mika Westerberg's avatar Mika Westerberg

thunderbolt: Generalize tunnel creation functionality

To be able to tunnel non-PCIe traffic, separate tunnel functionality
into generic and PCIe specific parts. Rename struct tb_pci_tunnel to
tb_tunnel, and make it hold an array of paths instead of just two.
Update all the tunneling functions to take this structure as parameter.

We also move tb_pci_port_active() to switch.c (and rename it) where we
will be keeping all port and switch related functions.
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
parent 1752b9f7
......@@ -599,6 +599,19 @@ static int tb_init_port(struct tb_port *port)
}
/**
* tb_pci_port_enable() - Enable PCIe adapter port
* @port: PCIe port to enable
* @enable: Enable/disable the PCIe adapter
*/
int tb_pci_port_enable(struct tb_port *port, bool enable)
{
u32 word = enable ? TB_PCI_EN : 0x0;
if (!port->cap_adap)
return -ENXIO;
return tb_port_write(port, &word, TB_CFG_PORT, port->cap_adap, 1);
}
/* switch utility functions */
static void tb_dump_switch(struct tb *tb, struct tb_regs_switch_header *sw)
......
......@@ -91,14 +91,14 @@ static void tb_scan_port(struct tb_port *port)
static void tb_free_invalid_tunnels(struct tb *tb)
{
struct tb_cm *tcm = tb_priv(tb);
struct tb_pci_tunnel *tunnel;
struct tb_pci_tunnel *n;
struct tb_tunnel *tunnel;
struct tb_tunnel *n;
list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) {
if (tb_pci_is_invalid(tunnel)) {
tb_pci_deactivate(tunnel);
if (tb_tunnel_is_invalid(tunnel)) {
tb_tunnel_deactivate(tunnel);
list_del(&tunnel->list);
tb_pci_free(tunnel);
tb_tunnel_free(tunnel);
}
}
}
......@@ -178,7 +178,7 @@ static void tb_activate_pcie_devices(struct tb *tb)
struct tb_switch *sw;
struct tb_port *up_port;
struct tb_port *down_port;
struct tb_pci_tunnel *tunnel;
struct tb_tunnel *tunnel;
struct tb_cm *tcm = tb_priv(tb);
/* scan for pcie devices at depth 1*/
......@@ -214,17 +214,17 @@ static void tb_activate_pcie_devices(struct tb *tb)
"All PCIe down ports are occupied, aborting\n");
continue;
}
tunnel = tb_pci_alloc(tb, up_port, down_port);
tunnel = tb_tunnel_alloc_pci(tb, up_port, down_port);
if (!tunnel) {
tb_port_info(up_port,
"PCIe tunnel allocation failed, aborting\n");
continue;
}
if (tb_pci_activate(tunnel)) {
if (tb_tunnel_activate(tunnel)) {
tb_port_info(up_port,
"PCIe tunnel activation failed, aborting\n");
tb_pci_free(tunnel);
tb_tunnel_free(tunnel);
continue;
}
......@@ -353,13 +353,13 @@ static void tb_handle_event(struct tb *tb, enum tb_cfg_pkg_type type,
static void tb_stop(struct tb *tb)
{
struct tb_cm *tcm = tb_priv(tb);
struct tb_pci_tunnel *tunnel;
struct tb_pci_tunnel *n;
struct tb_tunnel *tunnel;
struct tb_tunnel *n;
/* tunnels are only present after everything has been initialized */
list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) {
tb_pci_deactivate(tunnel);
tb_pci_free(tunnel);
tb_tunnel_deactivate(tunnel);
tb_tunnel_free(tunnel);
}
tb_switch_remove(tb->root_switch);
tcm->hotplug_active = false; /* signal tb_handle_hotplug to quit */
......@@ -418,7 +418,7 @@ static int tb_suspend_noirq(struct tb *tb)
static int tb_resume_noirq(struct tb *tb)
{
struct tb_cm *tcm = tb_priv(tb);
struct tb_pci_tunnel *tunnel, *n;
struct tb_tunnel *tunnel, *n;
tb_dbg(tb, "resuming...\n");
......@@ -429,7 +429,7 @@ static int tb_resume_noirq(struct tb *tb)
tb_free_invalid_tunnels(tb);
tb_free_unplugged_children(tb->root_switch);
list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list)
tb_pci_restart(tunnel);
tb_tunnel_restart(tunnel);
if (!list_empty(&tcm->tunnel_list)) {
/*
* the pcie links need some time to get going.
......
......@@ -457,6 +457,8 @@ int tb_port_clear_counter(struct tb_port *port, int counter);
int tb_switch_find_vse_cap(struct tb_switch *sw, enum tb_switch_vse_cap vsec);
int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap);
int tb_pci_port_enable(struct tb_port *port, bool enable);
struct tb_path *tb_path_alloc(struct tb *tb, int num_hops);
void tb_path_free(struct tb_path *path);
int tb_path_activate(struct tb_path *path);
......
......@@ -211,6 +211,10 @@ struct tb_regs_port_header {
} __packed;
/* PCIe adapter registers */
#define TB_PCI_EN BIT(31)
/* Hop register from TB_CFG_HOPS. 8 byte per entry. */
struct tb_regs_hop {
/* DWORD 0 */
......
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Thunderbolt Cactus Ridge driver - Tunneling support
* Thunderbolt driver - Tunneling support
*
* Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
* Copyright (C) 2019, Intel Corporation
*/
#ifndef TB_TUNNEL_H_
......@@ -10,22 +11,33 @@
#include "tb.h"
struct tb_pci_tunnel {
/**
* struct tb_tunnel - Tunnel between two ports
* @tb: Pointer to the domain
* @src_port: Source port of the tunnel
* @dst_port: Destination port of the tunnel
* @paths: All paths required by the tunnel
* @npaths: Number of paths in @paths
* @activate: Optional tunnel specific activation/deactivation
* @list: Tunnels are linked using this field
*/
struct tb_tunnel {
struct tb *tb;
struct tb_port *up_port;
struct tb_port *down_port;
struct tb_path *path_to_up;
struct tb_path *path_to_down;
struct tb_port *src_port;
struct tb_port *dst_port;
struct tb_path **paths;
size_t npaths;
int (*activate)(struct tb_tunnel *tunnel, bool activate);
struct list_head list;
};
struct tb_pci_tunnel *tb_pci_alloc(struct tb *tb, struct tb_port *up,
struct tb_port *down);
void tb_pci_free(struct tb_pci_tunnel *tunnel);
int tb_pci_activate(struct tb_pci_tunnel *tunnel);
int tb_pci_restart(struct tb_pci_tunnel *tunnel);
void tb_pci_deactivate(struct tb_pci_tunnel *tunnel);
bool tb_pci_is_invalid(struct tb_pci_tunnel *tunnel);
struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
struct tb_port *down);
void tb_tunnel_free(struct tb_tunnel *tunnel);
int tb_tunnel_activate(struct tb_tunnel *tunnel);
int tb_tunnel_restart(struct tb_tunnel *tunnel);
void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
#endif
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