blob: c68bbcd3a62c4f1b0ba68b8223420fcd5e5e4b09 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Andreas Noever3364f0c2014-06-03 22:04:08 +02002/*
Mika Westerberg93f36ad2017-02-19 13:48:29 +02003 * Thunderbolt driver - Tunneling support
Andreas Noever3364f0c2014-06-03 22:04:08 +02004 *
5 * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
Mika Westerberg93f36ad2017-02-19 13:48:29 +02006 * Copyright (C) 2019, Intel Corporation
Andreas Noever3364f0c2014-06-03 22:04:08 +02007 */
8
Mika Westerberg1752b9f2017-02-19 10:58:35 +02009#ifndef TB_TUNNEL_H_
10#define TB_TUNNEL_H_
Andreas Noever3364f0c2014-06-03 22:04:08 +020011
12#include "tb.h"
13
Mika Westerberg4f807e42018-09-17 16:30:49 +030014enum tb_tunnel_type {
15 TB_TUNNEL_PCI,
16 TB_TUNNEL_DP,
Mika Westerberg44242d62018-09-28 16:35:32 +030017 TB_TUNNEL_DMA,
Mika Westerberg4f807e42018-09-17 16:30:49 +030018};
19
Mika Westerberg93f36ad2017-02-19 13:48:29 +020020/**
21 * struct tb_tunnel - Tunnel between two ports
22 * @tb: Pointer to the domain
23 * @src_port: Source port of the tunnel
Mika Westerberg0414bec2017-02-19 23:43:26 +020024 * @dst_port: Destination port of the tunnel. For discovered incomplete
25 * tunnels may be %NULL or null adapter port instead.
Mika Westerberg93f36ad2017-02-19 13:48:29 +020026 * @paths: All paths required by the tunnel
27 * @npaths: Number of paths in @paths
Mika Westerberg4f807e42018-09-17 16:30:49 +030028 * @init: Optional tunnel specific initialization
Mika Westerberg93f36ad2017-02-19 13:48:29 +020029 * @activate: Optional tunnel specific activation/deactivation
30 * @list: Tunnels are linked using this field
Mika Westerberg4f807e42018-09-17 16:30:49 +030031 * @type: Type of the tunnel
Mika Westerberg93f36ad2017-02-19 13:48:29 +020032 */
33struct tb_tunnel {
Andreas Noever3364f0c2014-06-03 22:04:08 +020034 struct tb *tb;
Mika Westerberg93f36ad2017-02-19 13:48:29 +020035 struct tb_port *src_port;
36 struct tb_port *dst_port;
37 struct tb_path **paths;
38 size_t npaths;
Mika Westerberg4f807e42018-09-17 16:30:49 +030039 int (*init)(struct tb_tunnel *tunnel);
Mika Westerberg93f36ad2017-02-19 13:48:29 +020040 int (*activate)(struct tb_tunnel *tunnel, bool activate);
Andreas Noever3364f0c2014-06-03 22:04:08 +020041 struct list_head list;
Mika Westerberg4f807e42018-09-17 16:30:49 +030042 enum tb_tunnel_type type;
Andreas Noever3364f0c2014-06-03 22:04:08 +020043};
44
Mika Westerberg0414bec2017-02-19 23:43:26 +020045struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down);
Mika Westerberg93f36ad2017-02-19 13:48:29 +020046struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
47 struct tb_port *down);
Mika Westerberg4f807e42018-09-17 16:30:49 +030048struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in);
49struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
50 struct tb_port *out);
Mika Westerberg44242d62018-09-28 16:35:32 +030051struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
52 struct tb_port *dst, int transmit_ring,
53 int transmit_path, int receive_ring,
54 int receive_path);
Mika Westerberg4f807e42018-09-17 16:30:49 +030055
Mika Westerberg93f36ad2017-02-19 13:48:29 +020056void tb_tunnel_free(struct tb_tunnel *tunnel);
57int tb_tunnel_activate(struct tb_tunnel *tunnel);
58int tb_tunnel_restart(struct tb_tunnel *tunnel);
59void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
60bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
Andreas Noever3364f0c2014-06-03 22:04:08 +020061
Mika Westerberg4f807e42018-09-17 16:30:49 +030062static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
63{
64 return tunnel->type == TB_TUNNEL_PCI;
65}
66
67static inline bool tb_tunnel_is_dp(const struct tb_tunnel *tunnel)
68{
69 return tunnel->type == TB_TUNNEL_DP;
70}
71
Mika Westerberg44242d62018-09-28 16:35:32 +030072static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel)
73{
74 return tunnel->type == TB_TUNNEL_DMA;
75}
76
Andreas Noever3364f0c2014-06-03 22:04:08 +020077#endif
78