xref: /openbmc/linux/drivers/thunderbolt/tunnel.h (revision 3381df09)
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 	TB_TUNNEL_USB3,
19 };
20 
21 /**
22  * struct tb_tunnel - Tunnel between two ports
23  * @tb: Pointer to the domain
24  * @src_port: Source port of the tunnel
25  * @dst_port: Destination port of the tunnel. For discovered incomplete
26  *	      tunnels may be %NULL or null adapter port instead.
27  * @paths: All paths required by the tunnel
28  * @npaths: Number of paths in @paths
29  * @init: Optional tunnel specific initialization
30  * @activate: Optional tunnel specific activation/deactivation
31  * @consumed_bandwidth: Return how much bandwidth the tunnel consumes
32  * @list: Tunnels are linked using this field
33  * @type: Type of the tunnel
34  * @max_bw: Maximum bandwidth (Mb/s) available for the tunnel (only for DP).
35  *	    Only set if the bandwidth needs to be limited.
36  */
37 struct tb_tunnel {
38 	struct tb *tb;
39 	struct tb_port *src_port;
40 	struct tb_port *dst_port;
41 	struct tb_path **paths;
42 	size_t npaths;
43 	int (*init)(struct tb_tunnel *tunnel);
44 	int (*activate)(struct tb_tunnel *tunnel, bool activate);
45 	int (*consumed_bandwidth)(struct tb_tunnel *tunnel);
46 	struct list_head list;
47 	enum tb_tunnel_type type;
48 	unsigned int max_bw;
49 };
50 
51 struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down);
52 struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
53 				      struct tb_port *down);
54 struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in);
55 struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
56 				     struct tb_port *out, int max_bw);
57 struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
58 				      struct tb_port *dst, int transmit_ring,
59 				      int transmit_path, int receive_ring,
60 				      int receive_path);
61 struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down);
62 struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up,
63 				       struct tb_port *down);
64 
65 void tb_tunnel_free(struct tb_tunnel *tunnel);
66 int tb_tunnel_activate(struct tb_tunnel *tunnel);
67 int tb_tunnel_restart(struct tb_tunnel *tunnel);
68 void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
69 bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
70 bool tb_tunnel_switch_on_path(const struct tb_tunnel *tunnel,
71 			      const struct tb_switch *sw);
72 int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel);
73 
74 static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
75 {
76 	return tunnel->type == TB_TUNNEL_PCI;
77 }
78 
79 static inline bool tb_tunnel_is_dp(const struct tb_tunnel *tunnel)
80 {
81 	return tunnel->type == TB_TUNNEL_DP;
82 }
83 
84 static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel)
85 {
86 	return tunnel->type == TB_TUNNEL_DMA;
87 }
88 
89 static inline bool tb_tunnel_is_usb3(const struct tb_tunnel *tunnel)
90 {
91 	return tunnel->type == TB_TUNNEL_USB3;
92 }
93 
94 #endif
95 
96