drm/atomic-helper: document drm_atomic_helper_check() restrictions
[drm/drm-misc.git] / include / linux / greybus / connection.h
blobd59b7fc1de3e10e585e966c0633276f813e6f07a
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Greybus connections
5 * Copyright 2014 Google Inc.
6 * Copyright 2014 Linaro Ltd.
7 */
9 #ifndef __CONNECTION_H
10 #define __CONNECTION_H
12 #include <linux/bits.h>
13 #include <linux/list.h>
14 #include <linux/kfifo.h>
15 #include <linux/kref.h>
16 #include <linux/workqueue.h>
18 #define GB_CONNECTION_FLAG_CSD BIT(0)
19 #define GB_CONNECTION_FLAG_NO_FLOWCTRL BIT(1)
20 #define GB_CONNECTION_FLAG_OFFLOADED BIT(2)
21 #define GB_CONNECTION_FLAG_CDSI1 BIT(3)
22 #define GB_CONNECTION_FLAG_CONTROL BIT(4)
23 #define GB_CONNECTION_FLAG_HIGH_PRIO BIT(5)
25 #define GB_CONNECTION_FLAG_CORE_MASK GB_CONNECTION_FLAG_CONTROL
27 enum gb_connection_state {
28 GB_CONNECTION_STATE_DISABLED = 0,
29 GB_CONNECTION_STATE_ENABLED_TX = 1,
30 GB_CONNECTION_STATE_ENABLED = 2,
31 GB_CONNECTION_STATE_DISCONNECTING = 3,
34 struct gb_operation;
36 typedef int (*gb_request_handler_t)(struct gb_operation *);
38 struct gb_connection {
39 struct gb_host_device *hd;
40 struct gb_interface *intf;
41 struct gb_bundle *bundle;
42 struct kref kref;
43 u16 hd_cport_id;
44 u16 intf_cport_id;
46 struct list_head hd_links;
47 struct list_head bundle_links;
49 gb_request_handler_t handler;
50 unsigned long flags;
52 struct mutex mutex;
53 spinlock_t lock;
54 enum gb_connection_state state;
55 struct list_head operations;
57 char name[16];
58 struct workqueue_struct *wq;
60 atomic_t op_cycle;
62 void *private;
64 bool mode_switch;
67 struct gb_connection *gb_connection_create_static(struct gb_host_device *hd,
68 u16 hd_cport_id, gb_request_handler_t handler);
69 struct gb_connection *gb_connection_create_control(struct gb_interface *intf);
70 struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
71 u16 cport_id, gb_request_handler_t handler);
72 struct gb_connection *gb_connection_create_flags(struct gb_bundle *bundle,
73 u16 cport_id, gb_request_handler_t handler,
74 unsigned long flags);
75 struct gb_connection *gb_connection_create_offloaded(struct gb_bundle *bundle,
76 u16 cport_id, unsigned long flags);
77 void gb_connection_destroy(struct gb_connection *connection);
79 static inline bool gb_connection_is_static(struct gb_connection *connection)
81 return !connection->intf;
84 int gb_connection_enable(struct gb_connection *connection);
85 int gb_connection_enable_tx(struct gb_connection *connection);
86 void gb_connection_disable_rx(struct gb_connection *connection);
87 void gb_connection_disable(struct gb_connection *connection);
88 void gb_connection_disable_forced(struct gb_connection *connection);
90 void gb_connection_mode_switch_prepare(struct gb_connection *connection);
91 void gb_connection_mode_switch_complete(struct gb_connection *connection);
93 void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
94 u8 *data, size_t length);
96 void gb_connection_latency_tag_enable(struct gb_connection *connection);
97 void gb_connection_latency_tag_disable(struct gb_connection *connection);
99 static inline bool gb_connection_e2efc_enabled(struct gb_connection *connection)
101 return !(connection->flags & GB_CONNECTION_FLAG_CSD);
104 static inline bool
105 gb_connection_flow_control_disabled(struct gb_connection *connection)
107 return connection->flags & GB_CONNECTION_FLAG_NO_FLOWCTRL;
110 static inline bool gb_connection_is_offloaded(struct gb_connection *connection)
112 return connection->flags & GB_CONNECTION_FLAG_OFFLOADED;
115 static inline bool gb_connection_is_control(struct gb_connection *connection)
117 return connection->flags & GB_CONNECTION_FLAG_CONTROL;
120 static inline void *gb_connection_get_data(struct gb_connection *connection)
122 return connection->private;
125 static inline void gb_connection_set_data(struct gb_connection *connection,
126 void *data)
128 connection->private = data;
131 #endif /* __CONNECTION_H */