connection.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Greybus connections
  4. *
  5. * Copyright 2014 Google Inc.
  6. * Copyright 2014 Linaro Ltd.
  7. */
  8. #ifndef __CONNECTION_H
  9. #define __CONNECTION_H
  10. #include <linux/bits.h>
  11. #include <linux/list.h>
  12. #include <linux/kfifo.h>
  13. #include <linux/kref.h>
  14. #include <linux/workqueue.h>
  15. #define GB_CONNECTION_FLAG_CSD BIT(0)
  16. #define GB_CONNECTION_FLAG_NO_FLOWCTRL BIT(1)
  17. #define GB_CONNECTION_FLAG_OFFLOADED BIT(2)
  18. #define GB_CONNECTION_FLAG_CDSI1 BIT(3)
  19. #define GB_CONNECTION_FLAG_CONTROL BIT(4)
  20. #define GB_CONNECTION_FLAG_HIGH_PRIO BIT(5)
  21. #define GB_CONNECTION_FLAG_CORE_MASK GB_CONNECTION_FLAG_CONTROL
  22. enum gb_connection_state {
  23. GB_CONNECTION_STATE_DISABLED = 0,
  24. GB_CONNECTION_STATE_ENABLED_TX = 1,
  25. GB_CONNECTION_STATE_ENABLED = 2,
  26. GB_CONNECTION_STATE_DISCONNECTING = 3,
  27. };
  28. struct gb_operation;
  29. typedef int (*gb_request_handler_t)(struct gb_operation *);
  30. struct gb_connection {
  31. struct gb_host_device *hd;
  32. struct gb_interface *intf;
  33. struct gb_bundle *bundle;
  34. struct kref kref;
  35. u16 hd_cport_id;
  36. u16 intf_cport_id;
  37. struct list_head hd_links;
  38. struct list_head bundle_links;
  39. gb_request_handler_t handler;
  40. unsigned long flags;
  41. struct mutex mutex;
  42. spinlock_t lock;
  43. enum gb_connection_state state;
  44. struct list_head operations;
  45. char name[16];
  46. struct workqueue_struct *wq;
  47. atomic_t op_cycle;
  48. void *private;
  49. bool mode_switch;
  50. };
  51. struct gb_connection *gb_connection_create_static(struct gb_host_device *hd,
  52. u16 hd_cport_id, gb_request_handler_t handler);
  53. struct gb_connection *gb_connection_create_control(struct gb_interface *intf);
  54. struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
  55. u16 cport_id, gb_request_handler_t handler);
  56. struct gb_connection *gb_connection_create_flags(struct gb_bundle *bundle,
  57. u16 cport_id, gb_request_handler_t handler,
  58. unsigned long flags);
  59. struct gb_connection *gb_connection_create_offloaded(struct gb_bundle *bundle,
  60. u16 cport_id, unsigned long flags);
  61. void gb_connection_destroy(struct gb_connection *connection);
  62. static inline bool gb_connection_is_static(struct gb_connection *connection)
  63. {
  64. return !connection->intf;
  65. }
  66. int gb_connection_enable(struct gb_connection *connection);
  67. int gb_connection_enable_tx(struct gb_connection *connection);
  68. void gb_connection_disable_rx(struct gb_connection *connection);
  69. void gb_connection_disable(struct gb_connection *connection);
  70. void gb_connection_disable_forced(struct gb_connection *connection);
  71. void gb_connection_mode_switch_prepare(struct gb_connection *connection);
  72. void gb_connection_mode_switch_complete(struct gb_connection *connection);
  73. void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
  74. u8 *data, size_t length);
  75. void gb_connection_latency_tag_enable(struct gb_connection *connection);
  76. void gb_connection_latency_tag_disable(struct gb_connection *connection);
  77. static inline bool gb_connection_e2efc_enabled(struct gb_connection *connection)
  78. {
  79. return !(connection->flags & GB_CONNECTION_FLAG_CSD);
  80. }
  81. static inline bool
  82. gb_connection_flow_control_disabled(struct gb_connection *connection)
  83. {
  84. return connection->flags & GB_CONNECTION_FLAG_NO_FLOWCTRL;
  85. }
  86. static inline bool gb_connection_is_offloaded(struct gb_connection *connection)
  87. {
  88. return connection->flags & GB_CONNECTION_FLAG_OFFLOADED;
  89. }
  90. static inline bool gb_connection_is_control(struct gb_connection *connection)
  91. {
  92. return connection->flags & GB_CONNECTION_FLAG_CONTROL;
  93. }
  94. static inline void *gb_connection_get_data(struct gb_connection *connection)
  95. {
  96. return connection->private;
  97. }
  98. static inline void gb_connection_set_data(struct gb_connection *connection,
  99. void *data)
  100. {
  101. connection->private = data;
  102. }
  103. #endif /* __CONNECTION_H */