Source
x
// SPDX-License-Identifier: GPL-2.0
/*
* Thunderbolt Cactus Ridge driver - PCIe tunnel
*
* Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
*/
static void tb_pci_init_path(struct tb_path *path)
{
path->egress_fc_enable = TB_PATH_SOURCE | TB_PATH_INTERNAL;
path->egress_shared_buffer = TB_PATH_NONE;
path->ingress_fc_enable = TB_PATH_ALL;
path->ingress_shared_buffer = TB_PATH_NONE;
path->priority = 3;
path->weight = 1;
path->drop_packages = 0;
path->nfc_credits = 0;
}
/**
* tb_pci_alloc() - allocate a pci tunnel
*
* Allocate a PCI tunnel. The ports must be of type TB_TYPE_PCIE_UP and
* TB_TYPE_PCIE_DOWN.
*
* Currently only paths consisting of two hops are supported (that is the
* ports must be on "adjacent" switches).
*
* The paths are hard-coded to use hop 8 (the only working hop id available on
* my thunderbolt devices). Therefore at most ONE path per device may be
* activated.
*
* Return: Returns a tb_pci_tunnel on success or NULL on failure.
*/
struct tb_pci_tunnel *tb_pci_alloc(struct tb *tb, struct tb_port *up,
struct tb_port *down)
{
struct tb_pci_tunnel *tunnel = kzalloc(sizeof(*tunnel), GFP_KERNEL);
if (!tunnel)
goto err;
tunnel->tb = tb;
tunnel->down_port = down;
tunnel->up_port = up;
INIT_LIST_HEAD(&tunnel->list);
tunnel->path_to_up = tb_path_alloc(up->sw->tb, 2);
if (!tunnel->path_to_up)
goto err;
tunnel->path_to_down = tb_path_alloc(up->sw->tb, 2);
if (!tunnel->path_to_down)
goto err;
tb_pci_init_path(tunnel->path_to_up);
tb_pci_init_path(tunnel->path_to_down);
tunnel->path_to_up->hops[0].in_port = down;
tunnel->path_to_up->hops[0].in_hop_index = 8;
tunnel->path_to_up->hops[0].in_counter_index = -1;
tunnel->path_to_up->hops[0].out_port = tb_upstream_port(up->sw)->remote;
tunnel->path_to_up->hops[0].next_hop_index = 8;
tunnel->path_to_up->hops[1].in_port = tb_upstream_port(up->sw);
tunnel->path_to_up->hops[1].in_hop_index = 8;
tunnel->path_to_up->hops[1].in_counter_index = -1;
tunnel->path_to_up->hops[1].out_port = up;
tunnel->path_to_up->hops[1].next_hop_index = 8;
tunnel->path_to_down->hops[0].in_port = up;
tunnel->path_to_down->hops[0].in_hop_index = 8;
tunnel->path_to_down->hops[0].in_counter_index = -1;