greybus: use protocol_id for numeric values
[cascardo/linux.git] / drivers / staging / greybus / connection.h
1 /*
2  * Greybus connections
3  *
4  * Copyright 2014 Google Inc.
5  *
6  * Released under the GPLv2 only.
7  */
8
9 #ifndef __CONNECTION_H
10 #define __CONNECTION_H
11
12 #include <linux/list.h>
13
14 #include "greybus.h"
15
16 enum gb_connection_state {
17         GB_CONNECTION_STATE_INVALID     = 0,
18         GB_CONNECTION_STATE_DISABLED    = 1,
19         GB_CONNECTION_STATE_ENABLED     = 2,
20         GB_CONNECTION_STATE_ERROR       = 3,
21         GB_CONNECTION_STATE_DESTROYING  = 4,
22 };
23
24 struct gb_connection;
25 typedef int (*gb_connection_init_t)(struct gb_connection *);
26 typedef void (*gb_connection_exit_t)(struct gb_connection *);
27
28 struct gb_connection_handler {
29         gb_connection_init_t    connection_init;
30         gb_connection_exit_t    connection_exit;
31 };
32
33 struct gb_connection {
34         struct greybus_host_device      *hd;
35         struct gb_interface             *interface;
36         struct device                   dev;
37         u16                             hd_cport_id;
38         u16                             interface_cport_id;
39
40         struct rb_node                  hd_node;
41         struct list_head                interface_links;
42         u8                              protocol_id;
43
44         enum gb_connection_state        state;
45
46         struct list_head                operations;
47         struct rb_root                  pending;        /* awaiting reponse */
48         atomic_t                        op_cycle;
49
50         struct gb_connection_handler    *handler;
51
52         void                            *private;
53 };
54 #define to_gb_connection(d) container_of(d, struct gb_connection, dev)
55
56 struct gb_connection *gb_connection_create(struct gb_interface *interface,
57                                 u16 cport_id, u8 protocol_id);
58 void gb_connection_destroy(struct gb_connection *connection);
59
60 int gb_connection_init(struct gb_connection *connection);
61 void gb_connection_exit(struct gb_connection *connection);
62
63 struct gb_connection *gb_hd_connection_find(struct greybus_host_device *hd,
64                                 u16 cport_id);
65
66 u16 gb_connection_operation_id(struct gb_connection *connection);
67
68 __printf(2, 3)
69 void gb_connection_err(struct gb_connection *connection, const char *fmt, ...);
70
71 #endif /* __CONNECTION_H */