xref: /OK3568_Linux_fs/kernel/drivers/thunderbolt/tunnel.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Thunderbolt driver - Tunneling support
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
6*4882a593Smuzhiyun  * Copyright (C) 2019, Intel Corporation
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef TB_TUNNEL_H_
10*4882a593Smuzhiyun #define TB_TUNNEL_H_
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include "tb.h"
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun enum tb_tunnel_type {
15*4882a593Smuzhiyun 	TB_TUNNEL_PCI,
16*4882a593Smuzhiyun 	TB_TUNNEL_DP,
17*4882a593Smuzhiyun 	TB_TUNNEL_DMA,
18*4882a593Smuzhiyun 	TB_TUNNEL_USB3,
19*4882a593Smuzhiyun };
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /**
22*4882a593Smuzhiyun  * struct tb_tunnel - Tunnel between two ports
23*4882a593Smuzhiyun  * @tb: Pointer to the domain
24*4882a593Smuzhiyun  * @src_port: Source port of the tunnel
25*4882a593Smuzhiyun  * @dst_port: Destination port of the tunnel. For discovered incomplete
26*4882a593Smuzhiyun  *	      tunnels may be %NULL or null adapter port instead.
27*4882a593Smuzhiyun  * @paths: All paths required by the tunnel
28*4882a593Smuzhiyun  * @npaths: Number of paths in @paths
29*4882a593Smuzhiyun  * @init: Optional tunnel specific initialization
30*4882a593Smuzhiyun  * @activate: Optional tunnel specific activation/deactivation
31*4882a593Smuzhiyun  * @consumed_bandwidth: Return how much bandwidth the tunnel consumes
32*4882a593Smuzhiyun  * @release_unused_bandwidth: Release all unused bandwidth
33*4882a593Smuzhiyun  * @reclaim_available_bandwidth: Reclaim back available bandwidth
34*4882a593Smuzhiyun  * @list: Tunnels are linked using this field
35*4882a593Smuzhiyun  * @type: Type of the tunnel
36*4882a593Smuzhiyun  * @max_up: Maximum upstream bandwidth (Mb/s) available for the tunnel.
37*4882a593Smuzhiyun  *	    Only set if the bandwidth needs to be limited.
38*4882a593Smuzhiyun  * @max_down: Maximum downstream bandwidth (Mb/s) available for the tunnel.
39*4882a593Smuzhiyun  *	      Only set if the bandwidth needs to be limited.
40*4882a593Smuzhiyun  * @allocated_up: Allocated upstream bandwidth (only for USB3)
41*4882a593Smuzhiyun  * @allocated_down: Allocated downstream bandwidth (only for USB3)
42*4882a593Smuzhiyun  */
43*4882a593Smuzhiyun struct tb_tunnel {
44*4882a593Smuzhiyun 	struct tb *tb;
45*4882a593Smuzhiyun 	struct tb_port *src_port;
46*4882a593Smuzhiyun 	struct tb_port *dst_port;
47*4882a593Smuzhiyun 	struct tb_path **paths;
48*4882a593Smuzhiyun 	size_t npaths;
49*4882a593Smuzhiyun 	int (*init)(struct tb_tunnel *tunnel);
50*4882a593Smuzhiyun 	int (*activate)(struct tb_tunnel *tunnel, bool activate);
51*4882a593Smuzhiyun 	int (*consumed_bandwidth)(struct tb_tunnel *tunnel, int *consumed_up,
52*4882a593Smuzhiyun 				  int *consumed_down);
53*4882a593Smuzhiyun 	int (*release_unused_bandwidth)(struct tb_tunnel *tunnel);
54*4882a593Smuzhiyun 	void (*reclaim_available_bandwidth)(struct tb_tunnel *tunnel,
55*4882a593Smuzhiyun 					    int *available_up,
56*4882a593Smuzhiyun 					    int *available_down);
57*4882a593Smuzhiyun 	struct list_head list;
58*4882a593Smuzhiyun 	enum tb_tunnel_type type;
59*4882a593Smuzhiyun 	int max_up;
60*4882a593Smuzhiyun 	int max_down;
61*4882a593Smuzhiyun 	int allocated_up;
62*4882a593Smuzhiyun 	int allocated_down;
63*4882a593Smuzhiyun };
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down);
66*4882a593Smuzhiyun struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
67*4882a593Smuzhiyun 				      struct tb_port *down);
68*4882a593Smuzhiyun struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in);
69*4882a593Smuzhiyun struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
70*4882a593Smuzhiyun 				     struct tb_port *out, int max_up,
71*4882a593Smuzhiyun 				     int max_down);
72*4882a593Smuzhiyun struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
73*4882a593Smuzhiyun 				      struct tb_port *dst, int transmit_ring,
74*4882a593Smuzhiyun 				      int transmit_path, int receive_ring,
75*4882a593Smuzhiyun 				      int receive_path);
76*4882a593Smuzhiyun struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down);
77*4882a593Smuzhiyun struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up,
78*4882a593Smuzhiyun 				       struct tb_port *down, int max_up,
79*4882a593Smuzhiyun 				       int max_down);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun void tb_tunnel_free(struct tb_tunnel *tunnel);
82*4882a593Smuzhiyun int tb_tunnel_activate(struct tb_tunnel *tunnel);
83*4882a593Smuzhiyun int tb_tunnel_restart(struct tb_tunnel *tunnel);
84*4882a593Smuzhiyun void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
85*4882a593Smuzhiyun bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
86*4882a593Smuzhiyun bool tb_tunnel_port_on_path(const struct tb_tunnel *tunnel,
87*4882a593Smuzhiyun 			    const struct tb_port *port);
88*4882a593Smuzhiyun int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
89*4882a593Smuzhiyun 				 int *consumed_down);
90*4882a593Smuzhiyun int tb_tunnel_release_unused_bandwidth(struct tb_tunnel *tunnel);
91*4882a593Smuzhiyun void tb_tunnel_reclaim_available_bandwidth(struct tb_tunnel *tunnel,
92*4882a593Smuzhiyun 					   int *available_up,
93*4882a593Smuzhiyun 					   int *available_down);
94*4882a593Smuzhiyun 
tb_tunnel_is_pci(const struct tb_tunnel * tunnel)95*4882a593Smuzhiyun static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
96*4882a593Smuzhiyun {
97*4882a593Smuzhiyun 	return tunnel->type == TB_TUNNEL_PCI;
98*4882a593Smuzhiyun }
99*4882a593Smuzhiyun 
tb_tunnel_is_dp(const struct tb_tunnel * tunnel)100*4882a593Smuzhiyun static inline bool tb_tunnel_is_dp(const struct tb_tunnel *tunnel)
101*4882a593Smuzhiyun {
102*4882a593Smuzhiyun 	return tunnel->type == TB_TUNNEL_DP;
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun 
tb_tunnel_is_dma(const struct tb_tunnel * tunnel)105*4882a593Smuzhiyun static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel)
106*4882a593Smuzhiyun {
107*4882a593Smuzhiyun 	return tunnel->type == TB_TUNNEL_DMA;
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun 
tb_tunnel_is_usb3(const struct tb_tunnel * tunnel)110*4882a593Smuzhiyun static inline bool tb_tunnel_is_usb3(const struct tb_tunnel *tunnel)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun 	return tunnel->type == TB_TUNNEL_USB3;
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun #endif
116*4882a593Smuzhiyun 
117