greybus: connection: add unidirectional enabled state
[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 enum gb_connection_state {
17         GB_CONNECTION_STATE_INVALID     = 0,
18         GB_CONNECTION_STATE_DISABLED    = 1,
19         GB_CONNECTION_STATE_ENABLED_TX  = 2,
20         GB_CONNECTION_STATE_ENABLED     = 3,
21 };
22
23 struct gb_operation;
24
25 typedef int (*gb_request_handler_t)(struct gb_operation *);
26
27 struct gb_connection {
28         struct gb_host_device           *hd;
29         struct gb_interface             *intf;
30         struct gb_bundle                *bundle;
31         struct kref                     kref;
32         u16                             hd_cport_id;
33         u16                             intf_cport_id;
34
35         struct list_head                hd_links;
36         struct list_head                bundle_links;
37
38         gb_request_handler_t            handler;
39
40         struct gb_protocol              *protocol;
41         u8                              protocol_id;
42         u8                              major;
43         u8                              minor;
44         u8                              module_major;
45         u8                              module_minor;
46
47         struct mutex                    mutex;
48         spinlock_t                      lock;
49         enum gb_connection_state        state;
50         struct list_head                operations;
51
52         char                            name[16];
53         struct workqueue_struct         *wq;
54
55         atomic_t                        op_cycle;
56
57         void                            *private;
58 };
59
60 struct gb_connection *gb_connection_create_static(struct gb_host_device *hd,
61                                 u16 hd_cport_id, u8 protocol_id);
62 struct gb_connection *gb_connection_create_dynamic(struct gb_interface *intf,
63                                 struct gb_bundle *bundle, u16 cport_id,
64                                 u8 protocol_id);
65 void gb_connection_destroy(struct gb_connection *connection);
66
67 static inline bool gb_connection_is_static(struct gb_connection *connection)
68 {
69         return !connection->intf;
70 }
71
72 int gb_connection_enable(struct gb_connection *connection,
73                                         gb_request_handler_t handler);
74 static inline int gb_connection_enable_tx(struct gb_connection *connection)
75 {
76         return gb_connection_enable(connection, NULL);
77 }
78 void gb_connection_disable(struct gb_connection *connection);
79
80 int gb_connection_legacy_init(struct gb_connection *connection);
81 void gb_connection_legacy_exit(struct gb_connection *connection);
82
83 void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
84                         u8 *data, size_t length);
85
86 void gb_connection_latency_tag_enable(struct gb_connection *connection);
87 void gb_connection_latency_tag_disable(struct gb_connection *connection);
88
89 #endif /* __CONNECTION_H */