connection.h 3.6 KB

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