Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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