xref: /linux/drivers/thunderbolt/tunnel.h (revision 9a6b55ac)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Thunderbolt driver - Tunneling support
4  *
5  * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
6  * Copyright (C) 2019, Intel Corporation
7  */
8 
9 #ifndef TB_TUNNEL_H_
10 #define TB_TUNNEL_H_
11 
12 #include "tb.h"
13 
14 enum tb_tunnel_type {
15 	TB_TUNNEL_PCI,
16 	TB_TUNNEL_DP,
17 	TB_TUNNEL_DMA,
18 };
19 
20 /**
21  * struct tb_tunnel - Tunnel between two ports
22  * @tb: Pointer to the domain
23  * @src_port: Source port of the tunnel
24  * @dst_port: Destination port of the tunnel. For discovered incomplete
25  *	      tunnels may be %NULL or null adapter port instead.
26  * @paths: All paths required by the tunnel
27  * @npaths: Number of paths in @paths
28  * @init: Optional tunnel specific initialization
29  * @activate: Optional tunnel specific activation/deactivation
30  * @consumed_bandwidth: Return how much bandwidth the tunnel consumes
31  * @list: Tunnels are linked using this field
32  * @type: Type of the tunnel
33  * @max_bw: Maximum bandwidth (Mb/s) available for the tunnel (only for DP).
34  *	    Only set if the bandwidth needs to be limited.
35  */
36 struct tb_tunnel {
37 	struct tb *tb;
38 	struct tb_port *src_port;
39 	struct tb_port *dst_port;
40 	struct tb_path **paths;
41 	size_t npaths;
42 	int (*init)(struct tb_tunnel *tunnel);
43 	int (*activate)(struct tb_tunnel *tunnel, bool activate);
44 	int (*consumed_bandwidth)(struct tb_tunnel *tunnel);
45 	struct list_head list;
46 	enum tb_tunnel_type type;
47 	unsigned int max_bw;
48 };
49 
50 struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down);
51 struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
52 				      struct tb_port *down);
53 struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in);
54 struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
55 				     struct tb_port *out, int max_bw);
56 struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
57 				      struct tb_port *dst, int transmit_ring,
58 				      int transmit_path, int receive_ring,
59 				      int receive_path);
60 
61 void tb_tunnel_free(struct tb_tunnel *tunnel);
62 int tb_tunnel_activate(struct tb_tunnel *tunnel);
63 int tb_tunnel_restart(struct tb_tunnel *tunnel);
64 void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
65 bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
66 bool tb_tunnel_switch_on_path(const struct tb_tunnel *tunnel,
67 			      const struct tb_switch *sw);
68 int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel);
69 
70 static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
71 {
72 	return tunnel->type == TB_TUNNEL_PCI;
73 }
74 
75 static inline bool tb_tunnel_is_dp(const struct tb_tunnel *tunnel)
76 {
77 	return tunnel->type == TB_TUNNEL_DP;
78 }
79 
80 static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel)
81 {
82 	return tunnel->type == TB_TUNNEL_DMA;
83 }
84 
85 #endif
86 
87