Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Thunderbolt driver - Tunneling support
0004  *
0005  * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
0006  * Copyright (C) 2019, Intel Corporation
0007  */
0008 
0009 #ifndef TB_TUNNEL_H_
0010 #define TB_TUNNEL_H_
0011 
0012 #include "tb.h"
0013 
0014 enum tb_tunnel_type {
0015     TB_TUNNEL_PCI,
0016     TB_TUNNEL_DP,
0017     TB_TUNNEL_DMA,
0018     TB_TUNNEL_USB3,
0019 };
0020 
0021 /**
0022  * struct tb_tunnel - Tunnel between two ports
0023  * @tb: Pointer to the domain
0024  * @src_port: Source port of the tunnel
0025  * @dst_port: Destination port of the tunnel. For discovered incomplete
0026  *        tunnels may be %NULL or null adapter port instead.
0027  * @paths: All paths required by the tunnel
0028  * @npaths: Number of paths in @paths
0029  * @init: Optional tunnel specific initialization
0030  * @deinit: Optional tunnel specific de-initialization
0031  * @activate: Optional tunnel specific activation/deactivation
0032  * @consumed_bandwidth: Return how much bandwidth the tunnel consumes
0033  * @release_unused_bandwidth: Release all unused bandwidth
0034  * @reclaim_available_bandwidth: Reclaim back available bandwidth
0035  * @list: Tunnels are linked using this field
0036  * @type: Type of the tunnel
0037  * @max_up: Maximum upstream bandwidth (Mb/s) available for the tunnel.
0038  *      Only set if the bandwidth needs to be limited.
0039  * @max_down: Maximum downstream bandwidth (Mb/s) available for the tunnel.
0040  *        Only set if the bandwidth needs to be limited.
0041  * @allocated_up: Allocated upstream bandwidth (only for USB3)
0042  * @allocated_down: Allocated downstream bandwidth (only for USB3)
0043  */
0044 struct tb_tunnel {
0045     struct tb *tb;
0046     struct tb_port *src_port;
0047     struct tb_port *dst_port;
0048     struct tb_path **paths;
0049     size_t npaths;
0050     int (*init)(struct tb_tunnel *tunnel);
0051     void (*deinit)(struct tb_tunnel *tunnel);
0052     int (*activate)(struct tb_tunnel *tunnel, bool activate);
0053     int (*consumed_bandwidth)(struct tb_tunnel *tunnel, int *consumed_up,
0054                   int *consumed_down);
0055     int (*release_unused_bandwidth)(struct tb_tunnel *tunnel);
0056     void (*reclaim_available_bandwidth)(struct tb_tunnel *tunnel,
0057                         int *available_up,
0058                         int *available_down);
0059     struct list_head list;
0060     enum tb_tunnel_type type;
0061     int max_up;
0062     int max_down;
0063     int allocated_up;
0064     int allocated_down;
0065 };
0066 
0067 struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down,
0068                      bool alloc_hopid);
0069 struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
0070                       struct tb_port *down);
0071 struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in,
0072                     bool alloc_hopid);
0073 struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
0074                      struct tb_port *out, int link_nr,
0075                      int max_up, int max_down);
0076 struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
0077                       struct tb_port *dst, int transmit_path,
0078                       int transmit_ring, int receive_path,
0079                       int receive_ring);
0080 bool tb_tunnel_match_dma(const struct tb_tunnel *tunnel, int transmit_path,
0081              int transmit_ring, int receive_path, int receive_ring);
0082 struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down,
0083                       bool alloc_hopid);
0084 struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up,
0085                        struct tb_port *down, int max_up,
0086                        int max_down);
0087 
0088 void tb_tunnel_free(struct tb_tunnel *tunnel);
0089 int tb_tunnel_activate(struct tb_tunnel *tunnel);
0090 int tb_tunnel_restart(struct tb_tunnel *tunnel);
0091 void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
0092 bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
0093 bool tb_tunnel_port_on_path(const struct tb_tunnel *tunnel,
0094                 const struct tb_port *port);
0095 int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
0096                  int *consumed_down);
0097 int tb_tunnel_release_unused_bandwidth(struct tb_tunnel *tunnel);
0098 void tb_tunnel_reclaim_available_bandwidth(struct tb_tunnel *tunnel,
0099                        int *available_up,
0100                        int *available_down);
0101 
0102 static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
0103 {
0104     return tunnel->type == TB_TUNNEL_PCI;
0105 }
0106 
0107 static inline bool tb_tunnel_is_dp(const struct tb_tunnel *tunnel)
0108 {
0109     return tunnel->type == TB_TUNNEL_DP;
0110 }
0111 
0112 static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel)
0113 {
0114     return tunnel->type == TB_TUNNEL_DMA;
0115 }
0116 
0117 static inline bool tb_tunnel_is_usb3(const struct tb_tunnel *tunnel)
0118 {
0119     return tunnel->type == TB_TUNNEL_USB3;
0120 }
0121 
0122 #endif
0123