Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 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" |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 15 | |
Alex Elder | 36561f2 | 2014-10-22 02:04:30 -0500 | [diff] [blame] | 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 | |
Alex Elder | 3689f97 | 2014-10-27 06:04:30 -0500 | [diff] [blame] | 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 | |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 33 | struct gb_connection { |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 34 | struct greybus_host_device *hd; |
Alex Elder | cd34507 | 2014-10-02 12:30:05 -0500 | [diff] [blame] | 35 | struct gb_interface *interface; |
Greg Kroah-Hartman | f0f61b9 | 2014-10-24 17:34:46 +0800 | [diff] [blame] | 36 | struct device dev; |
Alex Elder | cd34507 | 2014-10-02 12:30:05 -0500 | [diff] [blame] | 37 | u16 hd_cport_id; |
| 38 | u16 interface_cport_id; |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 39 | |
Alex Elder | ee9ebe4 | 2014-10-06 06:53:08 -0500 | [diff] [blame] | 40 | struct rb_node hd_node; |
Alex Elder | cd34507 | 2014-10-02 12:30:05 -0500 | [diff] [blame] | 41 | struct list_head interface_links; |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame^] | 42 | |
| 43 | struct gb_protocol *protocol; |
| 44 | struct list_head protocol_links; |
Alex Elder | 7fba007 | 2014-10-28 19:35:59 -0500 | [diff] [blame] | 45 | |
Alex Elder | 36561f2 | 2014-10-22 02:04:30 -0500 | [diff] [blame] | 46 | enum gb_connection_state state; |
Alex Elder | e88afa5 | 2014-10-01 21:54:15 -0500 | [diff] [blame] | 47 | |
| 48 | struct list_head operations; |
Alex Elder | 84d148b | 2014-10-16 06:35:32 -0500 | [diff] [blame] | 49 | struct rb_root pending; /* awaiting reponse */ |
Alex Elder | e88afa5 | 2014-10-01 21:54:15 -0500 | [diff] [blame] | 50 | atomic_t op_cycle; |
Alex Elder | 8a30672 | 2014-10-03 15:05:21 -0500 | [diff] [blame] | 51 | |
Alex Elder | 3689f97 | 2014-10-27 06:04:30 -0500 | [diff] [blame] | 52 | struct gb_connection_handler *handler; |
| 53 | |
Alex Elder | 8a30672 | 2014-10-03 15:05:21 -0500 | [diff] [blame] | 54 | void *private; |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 55 | }; |
Greg Kroah-Hartman | f0f61b9 | 2014-10-24 17:34:46 +0800 | [diff] [blame] | 56 | #define to_gb_connection(d) container_of(d, struct gb_connection, dev) |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 57 | |
Alex Elder | cd34507 | 2014-10-02 12:30:05 -0500 | [diff] [blame] | 58 | struct gb_connection *gb_connection_create(struct gb_interface *interface, |
Alex Elder | 7fba007 | 2014-10-28 19:35:59 -0500 | [diff] [blame] | 59 | u16 cport_id, u8 protocol_id); |
Alex Elder | b05890d | 2014-10-02 12:30:01 -0500 | [diff] [blame] | 60 | void gb_connection_destroy(struct gb_connection *connection); |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 61 | |
Alex Elder | 574341c | 2014-10-16 06:35:35 -0500 | [diff] [blame] | 62 | int gb_connection_init(struct gb_connection *connection); |
Alex Elder | 697e55d | 2014-10-20 23:01:04 -0500 | [diff] [blame] | 63 | void gb_connection_exit(struct gb_connection *connection); |
Alex Elder | 574341c | 2014-10-16 06:35:35 -0500 | [diff] [blame] | 64 | |
Alex Elder | ee9ebe4 | 2014-10-06 06:53:08 -0500 | [diff] [blame] | 65 | struct gb_connection *gb_hd_connection_find(struct greybus_host_device *hd, |
| 66 | u16 cport_id); |
| 67 | |
Alex Elder | 84d148b | 2014-10-16 06:35:32 -0500 | [diff] [blame] | 68 | u16 gb_connection_operation_id(struct gb_connection *connection); |
Alex Elder | e88afa5 | 2014-10-01 21:54:15 -0500 | [diff] [blame] | 69 | |
Alex Elder | eeeed42 | 2014-10-03 15:05:22 -0500 | [diff] [blame] | 70 | __printf(2, 3) |
| 71 | void gb_connection_err(struct gb_connection *connection, const char *fmt, ...); |
| 72 | |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 73 | #endif /* __CONNECTION_H */ |