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