4 * Copyright 2014 Google Inc.
5 * Copyright 2014 Linaro Ltd.
7 * Released under the GPLv2 only.
10 #ifndef __CONNECTION_H
11 #define __CONNECTION_H
13 #include <linux/list.h>
14 #include <linux/kfifo.h>
16 #define GB_CONNECTION_FLAG_CSD BIT(0)
17 #define GB_CONNECTION_FLAG_NO_FLOWCTRL BIT(1)
18 #define GB_CONNECTION_FLAG_OFFLOADED BIT(2)
19 #define GB_CONNECTION_FLAG_CDSI1 BIT(3)
20 #define GB_CONNECTION_FLAG_CONTROL BIT(4)
21 #define GB_CONNECTION_FLAG_HIGH_PRIO BIT(5)
23 #define GB_CONNECTION_FLAG_CORE_MASK GB_CONNECTION_FLAG_CONTROL
25 enum gb_connection_state {
26 GB_CONNECTION_STATE_DISABLED = 0,
27 GB_CONNECTION_STATE_ENABLED_TX = 1,
28 GB_CONNECTION_STATE_ENABLED = 2,
29 GB_CONNECTION_STATE_DISCONNECTING = 3,
34 typedef int (*gb_request_handler_t)(struct gb_operation *);
36 struct gb_connection {
37 struct gb_host_device *hd;
38 struct gb_interface *intf;
39 struct gb_bundle *bundle;
44 struct list_head hd_links;
45 struct list_head bundle_links;
47 gb_request_handler_t handler;
52 enum gb_connection_state state;
53 struct list_head operations;
56 struct workqueue_struct *wq;
65 struct gb_connection *gb_connection_create_static(struct gb_host_device *hd,
66 u16 hd_cport_id, gb_request_handler_t handler);
67 struct gb_connection *gb_connection_create_control(struct gb_interface *intf);
68 struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
69 u16 cport_id, gb_request_handler_t handler);
70 struct gb_connection *gb_connection_create_flags(struct gb_bundle *bundle,
71 u16 cport_id, gb_request_handler_t handler,
73 struct gb_connection *gb_connection_create_offloaded(struct gb_bundle *bundle,
74 u16 cport_id, unsigned long flags);
75 void gb_connection_destroy(struct gb_connection *connection);
77 static inline bool gb_connection_is_static(struct gb_connection *connection)
79 return !connection->intf;
82 int gb_connection_enable(struct gb_connection *connection);
83 int gb_connection_enable_tx(struct gb_connection *connection);
84 void gb_connection_disable_rx(struct gb_connection *connection);
85 void gb_connection_disable(struct gb_connection *connection);
86 void gb_connection_disable_forced(struct gb_connection *connection);
88 void gb_connection_mode_switch_prepare(struct gb_connection *connection);
89 void gb_connection_mode_switch_complete(struct gb_connection *connection);
91 void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
92 u8 *data, size_t length);
94 void gb_connection_latency_tag_enable(struct gb_connection *connection);
95 void gb_connection_latency_tag_disable(struct gb_connection *connection);
97 static inline bool gb_connection_e2efc_enabled(struct gb_connection *connection)
99 return !(connection->flags & GB_CONNECTION_FLAG_CSD);
103 gb_connection_flow_control_disabled(struct gb_connection *connection)
105 return connection->flags & GB_CONNECTION_FLAG_NO_FLOWCTRL;
108 static inline bool gb_connection_is_offloaded(struct gb_connection *connection)
110 return connection->flags & GB_CONNECTION_FLAG_OFFLOADED;
113 static inline bool gb_connection_is_control(struct gb_connection *connection)
115 return connection->flags & GB_CONNECTION_FLAG_CONTROL;
118 static inline void *gb_connection_get_data(struct gb_connection *connection)
120 return connection->private;
123 static inline void gb_connection_set_data(struct gb_connection *connection,
126 connection->private = data;
129 #endif /* __CONNECTION_H */