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 | |
Johan Hovold | 64a6d13 | 2016-03-03 13:34:39 +0100 | [diff] [blame] | 16 | #define GB_CONNECTION_FLAG_CSD BIT(0) |
Johan Hovold | 0e9b41a | 2016-05-11 10:17:55 +0200 | [diff] [blame] | 17 | #define GB_CONNECTION_FLAG_NO_FLOWCTRL BIT(1) |
Johan Hovold | ca1f8f8 | 2016-05-11 10:17:56 +0200 | [diff] [blame] | 18 | #define GB_CONNECTION_FLAG_OFFLOADED BIT(2) |
Johan Hovold | 045d356 | 2016-05-11 10:18:04 +0200 | [diff] [blame^] | 19 | #define GB_CONNECTION_FLAG_CDSI1 BIT(3) |
Johan Hovold | 64a6d13 | 2016-03-03 13:34:39 +0100 | [diff] [blame] | 20 | |
Alex Elder | 36561f2 | 2014-10-22 02:04:30 -0500 | [diff] [blame] | 21 | enum gb_connection_state { |
| 22 | GB_CONNECTION_STATE_INVALID = 0, |
| 23 | GB_CONNECTION_STATE_DISABLED = 1, |
Johan Hovold | 570dfa7 | 2016-01-19 12:51:07 +0100 | [diff] [blame] | 24 | GB_CONNECTION_STATE_ENABLED_TX = 2, |
| 25 | GB_CONNECTION_STATE_ENABLED = 3, |
Alex Elder | 36561f2 | 2014-10-22 02:04:30 -0500 | [diff] [blame] | 26 | }; |
| 27 | |
Johan Hovold | bfa9a5e | 2016-01-19 12:51:02 +0100 | [diff] [blame] | 28 | struct gb_operation; |
| 29 | |
| 30 | typedef int (*gb_request_handler_t)(struct gb_operation *); |
| 31 | |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 32 | struct gb_connection { |
Johan Hovold | 2537636 | 2015-11-03 18:03:23 +0100 | [diff] [blame] | 33 | struct gb_host_device *hd; |
Johan Hovold | 2566fae | 2015-11-25 15:59:11 +0100 | [diff] [blame] | 34 | struct gb_interface *intf; |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 35 | struct gb_bundle *bundle; |
Greg Kroah-Hartman | b750fa3 | 2015-10-16 16:56:38 -0700 | [diff] [blame] | 36 | struct kref kref; |
Alex Elder | cd34507 | 2014-10-02 12:30:05 -0500 | [diff] [blame] | 37 | u16 hd_cport_id; |
Viresh Kumar | d7353ce | 2015-06-04 10:18:01 +0530 | [diff] [blame] | 38 | u16 intf_cport_id; |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 39 | |
Alex Elder | 2c43ce4 | 2014-11-17 08:08:44 -0600 | [diff] [blame] | 40 | struct list_head hd_links; |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 41 | struct list_head bundle_links; |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 42 | |
Johan Hovold | bfa9a5e | 2016-01-19 12:51:02 +0100 | [diff] [blame] | 43 | gb_request_handler_t handler; |
Johan Hovold | cb03318 | 2016-03-03 13:34:36 +0100 | [diff] [blame] | 44 | unsigned long flags; |
Johan Hovold | bfa9a5e | 2016-01-19 12:51:02 +0100 | [diff] [blame] | 45 | |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 46 | struct gb_protocol *protocol; |
Viresh Kumar | d653f4b1 | 2015-08-11 07:35:58 +0530 | [diff] [blame] | 47 | u8 module_major; |
| 48 | u8 module_minor; |
Alex Elder | 7fba007 | 2014-10-28 19:35:59 -0500 | [diff] [blame] | 49 | |
Johan Hovold | 2326878 | 2016-01-19 12:51:06 +0100 | [diff] [blame] | 50 | struct mutex mutex; |
Johan Hovold | cad09a8 | 2015-07-14 15:43:30 +0200 | [diff] [blame] | 51 | spinlock_t lock; |
Alex Elder | 36561f2 | 2014-10-22 02:04:30 -0500 | [diff] [blame] | 52 | enum gb_connection_state state; |
Johan Hovold | 008974c | 2015-07-14 15:43:31 +0200 | [diff] [blame] | 53 | struct list_head operations; |
Alex Elder | e88afa5 | 2014-10-01 21:54:15 -0500 | [diff] [blame] | 54 | |
Johan Hovold | 729b260 | 2015-11-25 15:59:14 +0100 | [diff] [blame] | 55 | char name[16]; |
Johan Hovold | 5a5bc35 | 2015-07-23 10:50:02 +0200 | [diff] [blame] | 56 | struct workqueue_struct *wq; |
| 57 | |
Alex Elder | 4afb7fd | 2014-12-03 08:35:08 -0600 | [diff] [blame] | 58 | atomic_t op_cycle; |
Alex Elder | 8a30672 | 2014-10-03 15:05:21 -0500 | [diff] [blame] | 59 | |
| 60 | void *private; |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 61 | }; |
| 62 | |
Johan Hovold | 2566fae | 2015-11-25 15:59:11 +0100 | [diff] [blame] | 63 | struct gb_connection *gb_connection_create_static(struct gb_host_device *hd, |
Johan Hovold | f7ee081 | 2016-01-21 17:34:21 +0100 | [diff] [blame] | 64 | u16 hd_cport_id, gb_request_handler_t handler); |
Johan Hovold | 59507e2 | 2016-01-21 17:34:12 +0100 | [diff] [blame] | 65 | struct gb_connection *gb_connection_create_control(struct gb_interface *intf); |
Johan Hovold | 96c2af5 | 2016-01-21 17:34:15 +0100 | [diff] [blame] | 66 | struct gb_connection *gb_connection_create(struct gb_bundle *bundle, |
Johan Hovold | f7ee081 | 2016-01-21 17:34:21 +0100 | [diff] [blame] | 67 | u16 cport_id, gb_request_handler_t handler); |
Johan Hovold | 781ac86 | 2016-05-11 10:17:57 +0200 | [diff] [blame] | 68 | struct gb_connection *gb_connection_create_flags(struct gb_bundle *bundle, |
Johan Hovold | cb03318 | 2016-03-03 13:34:36 +0100 | [diff] [blame] | 69 | u16 cport_id, gb_request_handler_t handler, |
| 70 | unsigned long flags); |
Johan Hovold | 781ac86 | 2016-05-11 10:17:57 +0200 | [diff] [blame] | 71 | struct gb_connection *gb_connection_create_offloaded(struct gb_bundle *bundle, |
| 72 | u16 cport_id, unsigned long flags); |
Alex Elder | b05890d | 2014-10-02 12:30:01 -0500 | [diff] [blame] | 73 | void gb_connection_destroy(struct gb_connection *connection); |
Alex Elder | 574341c | 2014-10-16 06:35:35 -0500 | [diff] [blame] | 74 | |
Johan Hovold | 4ec1574 | 2015-11-25 15:59:13 +0100 | [diff] [blame] | 75 | static inline bool gb_connection_is_static(struct gb_connection *connection) |
| 76 | { |
| 77 | return !connection->intf; |
| 78 | } |
| 79 | |
Johan Hovold | f7ee081 | 2016-01-21 17:34:21 +0100 | [diff] [blame] | 80 | int gb_connection_enable(struct gb_connection *connection); |
| 81 | int gb_connection_enable_tx(struct gb_connection *connection); |
Johan Hovold | beb6b7f | 2016-01-19 12:51:08 +0100 | [diff] [blame] | 82 | void gb_connection_disable_rx(struct gb_connection *connection); |
Johan Hovold | 6d3d950 | 2016-01-19 12:51:00 +0100 | [diff] [blame] | 83 | void gb_connection_disable(struct gb_connection *connection); |
| 84 | |
Johan Hovold | 2537636 | 2015-11-03 18:03:23 +0100 | [diff] [blame] | 85 | void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id, |
Alex Elder | 374e6a2 | 2014-11-17 18:08:37 -0600 | [diff] [blame] | 86 | u8 *data, size_t length); |
Alex Elder | eeeed42 | 2014-10-03 15:05:22 -0500 | [diff] [blame] | 87 | |
Bryan O'Donoghue | e7e2efc | 2015-10-15 16:10:42 +0100 | [diff] [blame] | 88 | void gb_connection_latency_tag_enable(struct gb_connection *connection); |
| 89 | void gb_connection_latency_tag_disable(struct gb_connection *connection); |
| 90 | |
Johan Hovold | 64a6d13 | 2016-03-03 13:34:39 +0100 | [diff] [blame] | 91 | static inline bool gb_connection_e2efc_enabled(struct gb_connection *connection) |
| 92 | { |
| 93 | return !(connection->flags & GB_CONNECTION_FLAG_CSD); |
| 94 | } |
| 95 | |
Johan Hovold | 0e9b41a | 2016-05-11 10:17:55 +0200 | [diff] [blame] | 96 | static inline bool |
| 97 | gb_connection_flow_control_disabled(struct gb_connection *connection) |
| 98 | { |
| 99 | return connection->flags & GB_CONNECTION_FLAG_NO_FLOWCTRL; |
| 100 | } |
| 101 | |
Johan Hovold | ca1f8f8 | 2016-05-11 10:17:56 +0200 | [diff] [blame] | 102 | static inline bool gb_connection_is_offloaded(struct gb_connection *connection) |
| 103 | { |
| 104 | return connection->flags & GB_CONNECTION_FLAG_OFFLOADED; |
| 105 | } |
| 106 | |
Greg Kroah-Hartman | 418f3da | 2016-03-22 14:30:16 -0400 | [diff] [blame] | 107 | static inline void *gb_connection_get_data(struct gb_connection *connection) |
| 108 | { |
| 109 | return connection->private; |
| 110 | } |
| 111 | |
| 112 | static inline void gb_connection_set_data(struct gb_connection *connection, |
| 113 | void *data) |
| 114 | { |
| 115 | connection->private = data; |
| 116 | } |
| 117 | |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 118 | #endif /* __CONNECTION_H */ |