Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Greybus connections |
| 3 | * |
| 4 | * Copyright 2014 Google Inc. |
Alex Elder | a46e967 | 2014-12-12 12:08:42 -0600 | [diff] [blame] | 5 | * Copyright 2014 Linaro Ltd. |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 6 | * |
| 7 | * Released under the GPLv2 only. |
| 8 | */ |
| 9 | |
| 10 | #ifndef __CONNECTION_H |
| 11 | #define __CONNECTION_H |
| 12 | |
| 13 | #include <linux/list.h> |
Bryan O'Donoghue | a1a4a29 | 2015-08-11 13:50:51 +0100 | [diff] [blame] | 14 | #include <linux/kfifo.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, |
Johan Hovold | 570dfa7 | 2016-01-19 12:51:07 +0100 | [diff] [blame] | 19 | GB_CONNECTION_STATE_ENABLED_TX = 2, |
| 20 | GB_CONNECTION_STATE_ENABLED = 3, |
Alex Elder | 36561f2 | 2014-10-22 02:04:30 -0500 | [diff] [blame] | 21 | }; |
| 22 | |
Johan Hovold | bfa9a5e | 2016-01-19 12:51:02 +0100 | [diff] [blame] | 23 | struct gb_operation; |
| 24 | |
| 25 | typedef int (*gb_request_handler_t)(struct gb_operation *); |
| 26 | |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 27 | struct gb_connection { |
Johan Hovold | 2537636 | 2015-11-03 18:03:23 +0100 | [diff] [blame] | 28 | struct gb_host_device *hd; |
Johan Hovold | 2566fae | 2015-11-25 15:59:11 +0100 | [diff] [blame] | 29 | struct gb_interface *intf; |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 30 | struct gb_bundle *bundle; |
Greg Kroah-Hartman | b750fa3 | 2015-10-16 16:56:38 -0700 | [diff] [blame] | 31 | struct kref kref; |
Alex Elder | cd34507 | 2014-10-02 12:30:05 -0500 | [diff] [blame] | 32 | u16 hd_cport_id; |
Viresh Kumar | d7353ce | 2015-06-04 10:18:01 +0530 | [diff] [blame] | 33 | u16 intf_cport_id; |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 34 | |
Alex Elder | 2c43ce4 | 2014-11-17 08:08:44 -0600 | [diff] [blame] | 35 | struct list_head hd_links; |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 36 | struct list_head bundle_links; |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 37 | |
Johan Hovold | bfa9a5e | 2016-01-19 12:51:02 +0100 | [diff] [blame] | 38 | gb_request_handler_t handler; |
| 39 | |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 40 | struct gb_protocol *protocol; |
Greg Kroah-Hartman | fb69cb5 | 2014-12-23 15:16:53 -0800 | [diff] [blame] | 41 | u8 protocol_id; |
| 42 | u8 major; |
| 43 | u8 minor; |
Viresh Kumar | d653f4b1 | 2015-08-11 07:35:58 +0530 | [diff] [blame] | 44 | u8 module_major; |
| 45 | u8 module_minor; |
Alex Elder | 7fba007 | 2014-10-28 19:35:59 -0500 | [diff] [blame] | 46 | |
Johan Hovold | 2326878 | 2016-01-19 12:51:06 +0100 | [diff] [blame] | 47 | struct mutex mutex; |
Johan Hovold | cad09a8 | 2015-07-14 15:43:30 +0200 | [diff] [blame] | 48 | spinlock_t lock; |
Alex Elder | 36561f2 | 2014-10-22 02:04:30 -0500 | [diff] [blame] | 49 | enum gb_connection_state state; |
Johan Hovold | 008974c | 2015-07-14 15:43:31 +0200 | [diff] [blame] | 50 | struct list_head operations; |
Alex Elder | e88afa5 | 2014-10-01 21:54:15 -0500 | [diff] [blame] | 51 | |
Johan Hovold | 729b260 | 2015-11-25 15:59:14 +0100 | [diff] [blame] | 52 | char name[16]; |
Johan Hovold | 5a5bc35 | 2015-07-23 10:50:02 +0200 | [diff] [blame] | 53 | struct workqueue_struct *wq; |
| 54 | |
Alex Elder | 4afb7fd | 2014-12-03 08:35:08 -0600 | [diff] [blame] | 55 | atomic_t op_cycle; |
Alex Elder | 8a30672 | 2014-10-03 15:05:21 -0500 | [diff] [blame] | 56 | |
| 57 | void *private; |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 58 | }; |
| 59 | |
Johan Hovold | 2566fae | 2015-11-25 15:59:11 +0100 | [diff] [blame] | 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); |
Alex Elder | b05890d | 2014-10-02 12:30:01 -0500 | [diff] [blame] | 65 | void gb_connection_destroy(struct gb_connection *connection); |
Alex Elder | 574341c | 2014-10-16 06:35:35 -0500 | [diff] [blame] | 66 | |
Johan Hovold | 4ec1574 | 2015-11-25 15:59:13 +0100 | [diff] [blame] | 67 | static inline bool gb_connection_is_static(struct gb_connection *connection) |
| 68 | { |
| 69 | return !connection->intf; |
| 70 | } |
| 71 | |
Johan Hovold | bfa9a5e | 2016-01-19 12:51:02 +0100 | [diff] [blame] | 72 | int gb_connection_enable(struct gb_connection *connection, |
| 73 | gb_request_handler_t handler); |
Johan Hovold | 570dfa7 | 2016-01-19 12:51:07 +0100 | [diff] [blame] | 74 | static inline int gb_connection_enable_tx(struct gb_connection *connection) |
| 75 | { |
| 76 | return gb_connection_enable(connection, NULL); |
| 77 | } |
Johan Hovold | beb6b7f | 2016-01-19 12:51:08 +0100 | [diff] [blame^] | 78 | void gb_connection_disable_rx(struct gb_connection *connection); |
Johan Hovold | 6d3d950 | 2016-01-19 12:51:00 +0100 | [diff] [blame] | 79 | void gb_connection_disable(struct gb_connection *connection); |
| 80 | |
| 81 | int gb_connection_legacy_init(struct gb_connection *connection); |
| 82 | void gb_connection_legacy_exit(struct gb_connection *connection); |
Johan Hovold | 0bf1f24 | 2015-12-07 15:05:34 +0100 | [diff] [blame] | 83 | |
Johan Hovold | 2537636 | 2015-11-03 18:03:23 +0100 | [diff] [blame] | 84 | void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id, |
Alex Elder | 374e6a2 | 2014-11-17 18:08:37 -0600 | [diff] [blame] | 85 | u8 *data, size_t length); |
Alex Elder | eeeed42 | 2014-10-03 15:05:22 -0500 | [diff] [blame] | 86 | |
Bryan O'Donoghue | e7e2efc | 2015-10-15 16:10:42 +0100 | [diff] [blame] | 87 | void gb_connection_latency_tag_enable(struct gb_connection *connection); |
| 88 | void gb_connection_latency_tag_disable(struct gb_connection *connection); |
| 89 | |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 90 | #endif /* __CONNECTION_H */ |