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 | |
Viresh Kumar | d653f4b1 | 2015-08-11 07:35:58 +0530 | [diff] [blame] | 46 | u8 module_major; |
| 47 | u8 module_minor; |
Alex Elder | 7fba007 | 2014-10-28 19:35:59 -0500 | [diff] [blame] | 48 | |
Johan Hovold | 2326878 | 2016-01-19 12:51:06 +0100 | [diff] [blame] | 49 | struct mutex mutex; |
Johan Hovold | cad09a8 | 2015-07-14 15:43:30 +0200 | [diff] [blame] | 50 | spinlock_t lock; |
Alex Elder | 36561f2 | 2014-10-22 02:04:30 -0500 | [diff] [blame] | 51 | enum gb_connection_state state; |
Johan Hovold | 008974c | 2015-07-14 15:43:31 +0200 | [diff] [blame] | 52 | struct list_head operations; |
Alex Elder | e88afa5 | 2014-10-01 21:54:15 -0500 | [diff] [blame] | 53 | |
Johan Hovold | 729b260 | 2015-11-25 15:59:14 +0100 | [diff] [blame] | 54 | char name[16]; |
Johan Hovold | 5a5bc35 | 2015-07-23 10:50:02 +0200 | [diff] [blame] | 55 | struct workqueue_struct *wq; |
| 56 | |
Alex Elder | 4afb7fd | 2014-12-03 08:35:08 -0600 | [diff] [blame] | 57 | atomic_t op_cycle; |
Alex Elder | 8a30672 | 2014-10-03 15:05:21 -0500 | [diff] [blame] | 58 | |
| 59 | void *private; |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 60 | }; |
| 61 | |
Johan Hovold | 2566fae | 2015-11-25 15:59:11 +0100 | [diff] [blame] | 62 | struct gb_connection *gb_connection_create_static(struct gb_host_device *hd, |
Johan Hovold | f7ee081 | 2016-01-21 17:34:21 +0100 | [diff] [blame] | 63 | u16 hd_cport_id, gb_request_handler_t handler); |
Johan Hovold | 59507e2 | 2016-01-21 17:34:12 +0100 | [diff] [blame] | 64 | struct gb_connection *gb_connection_create_control(struct gb_interface *intf); |
Johan Hovold | 96c2af5 | 2016-01-21 17:34:15 +0100 | [diff] [blame] | 65 | struct gb_connection *gb_connection_create(struct gb_bundle *bundle, |
Johan Hovold | f7ee081 | 2016-01-21 17:34:21 +0100 | [diff] [blame] | 66 | u16 cport_id, gb_request_handler_t handler); |
Johan Hovold | 781ac86 | 2016-05-11 10:17:57 +0200 | [diff] [blame] | 67 | struct gb_connection *gb_connection_create_flags(struct gb_bundle *bundle, |
Johan Hovold | cb03318 | 2016-03-03 13:34:36 +0100 | [diff] [blame] | 68 | u16 cport_id, gb_request_handler_t handler, |
| 69 | unsigned long flags); |
Johan Hovold | 781ac86 | 2016-05-11 10:17:57 +0200 | [diff] [blame] | 70 | struct gb_connection *gb_connection_create_offloaded(struct gb_bundle *bundle, |
| 71 | u16 cport_id, unsigned long flags); |
Alex Elder | b05890d | 2014-10-02 12:30:01 -0500 | [diff] [blame] | 72 | void gb_connection_destroy(struct gb_connection *connection); |
Alex Elder | 574341c | 2014-10-16 06:35:35 -0500 | [diff] [blame] | 73 | |
Johan Hovold | 4ec1574 | 2015-11-25 15:59:13 +0100 | [diff] [blame] | 74 | static inline bool gb_connection_is_static(struct gb_connection *connection) |
| 75 | { |
| 76 | return !connection->intf; |
| 77 | } |
| 78 | |
Johan Hovold | f7ee081 | 2016-01-21 17:34:21 +0100 | [diff] [blame] | 79 | int gb_connection_enable(struct gb_connection *connection); |
| 80 | int gb_connection_enable_tx(struct gb_connection *connection); |
Johan Hovold | beb6b7f | 2016-01-19 12:51:08 +0100 | [diff] [blame] | 81 | void gb_connection_disable_rx(struct gb_connection *connection); |
Johan Hovold | 6d3d950 | 2016-01-19 12:51:00 +0100 | [diff] [blame] | 82 | void gb_connection_disable(struct gb_connection *connection); |
| 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 | |
Johan Hovold | 64a6d13 | 2016-03-03 13:34:39 +0100 | [diff] [blame] | 90 | static inline bool gb_connection_e2efc_enabled(struct gb_connection *connection) |
| 91 | { |
| 92 | return !(connection->flags & GB_CONNECTION_FLAG_CSD); |
| 93 | } |
| 94 | |
Johan Hovold | 0e9b41a | 2016-05-11 10:17:55 +0200 | [diff] [blame] | 95 | static inline bool |
| 96 | gb_connection_flow_control_disabled(struct gb_connection *connection) |
| 97 | { |
| 98 | return connection->flags & GB_CONNECTION_FLAG_NO_FLOWCTRL; |
| 99 | } |
| 100 | |
Johan Hovold | ca1f8f8 | 2016-05-11 10:17:56 +0200 | [diff] [blame] | 101 | static inline bool gb_connection_is_offloaded(struct gb_connection *connection) |
| 102 | { |
| 103 | return connection->flags & GB_CONNECTION_FLAG_OFFLOADED; |
| 104 | } |
| 105 | |
Greg Kroah-Hartman | 418f3da | 2016-03-22 14:30:16 -0400 | [diff] [blame] | 106 | static inline void *gb_connection_get_data(struct gb_connection *connection) |
| 107 | { |
| 108 | return connection->private; |
| 109 | } |
| 110 | |
| 111 | static inline void gb_connection_set_data(struct gb_connection *connection, |
| 112 | void *data) |
| 113 | { |
| 114 | connection->private = data; |
| 115 | } |
| 116 | |
Alex Elder | c68adb2 | 2014-10-01 21:54:14 -0500 | [diff] [blame] | 117 | #endif /* __CONNECTION_H */ |