tunnel.h 3.9 KB

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