blob: 4d9f4c64176cb124a6663c37d358058f5383cd18 [file] [log] [blame]
Alex Elderc68adb22014-10-01 21:54:14 -05001/*
2 * Greybus connections
3 *
4 * Copyright 2014 Google Inc.
Alex Eldera46e9672014-12-12 12:08:42 -06005 * Copyright 2014 Linaro Ltd.
Alex Elderc68adb22014-10-01 21:54:14 -05006 *
7 * Released under the GPLv2 only.
8 */
9
10#ifndef __CONNECTION_H
11#define __CONNECTION_H
12
13#include <linux/list.h>
Bryan O'Donoghuea1a4a292015-08-11 13:50:51 +010014#include <linux/kfifo.h>
Alex Elderc68adb22014-10-01 21:54:14 -050015
Johan Hovold64a6d132016-03-03 13:34:39 +010016#define GB_CONNECTION_FLAG_CSD BIT(0)
Johan Hovold0e9b41a2016-05-11 10:17:55 +020017#define GB_CONNECTION_FLAG_NO_FLOWCTRL BIT(1)
Johan Hovoldca1f8f82016-05-11 10:17:56 +020018#define GB_CONNECTION_FLAG_OFFLOADED BIT(2)
Johan Hovold045d3562016-05-11 10:18:04 +020019#define GB_CONNECTION_FLAG_CDSI1 BIT(3)
Johan Hovoldaca7aab2016-05-27 17:26:25 +020020#define GB_CONNECTION_FLAG_CONTROL BIT(4)
Johan Hovold3094f9472016-06-22 11:42:04 +020021#define GB_CONNECTION_FLAG_HIGH_PRIO BIT(5)
Johan Hovold64a6d132016-03-03 13:34:39 +010022
Johan Hovold1ba30c32016-06-22 11:42:03 +020023#define GB_CONNECTION_FLAG_CORE_MASK GB_CONNECTION_FLAG_CONTROL
24
Alex Elder36561f22014-10-22 02:04:30 -050025enum gb_connection_state {
Johan Hovold3de5acf2016-05-27 17:26:36 +020026 GB_CONNECTION_STATE_DISABLED = 0,
27 GB_CONNECTION_STATE_ENABLED_TX = 1,
28 GB_CONNECTION_STATE_ENABLED = 2,
29 GB_CONNECTION_STATE_DISCONNECTING = 3,
Alex Elder36561f22014-10-22 02:04:30 -050030};
31
Johan Hovoldbfa9a5e2016-01-19 12:51:02 +010032struct gb_operation;
33
34typedef int (*gb_request_handler_t)(struct gb_operation *);
35
Alex Elderc68adb22014-10-01 21:54:14 -050036struct gb_connection {
Johan Hovold25376362015-11-03 18:03:23 +010037 struct gb_host_device *hd;
Johan Hovold2566fae62015-11-25 15:59:11 +010038 struct gb_interface *intf;
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -050039 struct gb_bundle *bundle;
Greg Kroah-Hartmanb750fa32015-10-16 16:56:38 -070040 struct kref kref;
Alex Eldercd345072014-10-02 12:30:05 -050041 u16 hd_cport_id;
Viresh Kumard7353ce2015-06-04 10:18:01 +053042 u16 intf_cport_id;
Alex Elderc68adb22014-10-01 21:54:14 -050043
Alex Elder2c43ce42014-11-17 08:08:44 -060044 struct list_head hd_links;
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -050045 struct list_head bundle_links;
Alex Elder4ccb6b72014-10-28 19:36:00 -050046
Johan Hovoldbfa9a5e2016-01-19 12:51:02 +010047 gb_request_handler_t handler;
Johan Hovoldcb033182016-03-03 13:34:36 +010048 unsigned long flags;
Johan Hovoldbfa9a5e2016-01-19 12:51:02 +010049
Johan Hovold23268782016-01-19 12:51:06 +010050 struct mutex mutex;
Johan Hovoldcad09a82015-07-14 15:43:30 +020051 spinlock_t lock;
Alex Elder36561f22014-10-22 02:04:30 -050052 enum gb_connection_state state;
Johan Hovold008974c2015-07-14 15:43:31 +020053 struct list_head operations;
Alex Eldere88afa52014-10-01 21:54:15 -050054
Johan Hovold729b2602015-11-25 15:59:14 +010055 char name[16];
Johan Hovold5a5bc352015-07-23 10:50:02 +020056 struct workqueue_struct *wq;
57
Alex Elder4afb7fd2014-12-03 08:35:08 -060058 atomic_t op_cycle;
Alex Elder8a306722014-10-03 15:05:21 -050059
60 void *private;
Johan Hovold55742d22016-05-27 17:26:40 +020061
62 bool mode_switch;
Alex Elderc68adb22014-10-01 21:54:14 -050063};
64
Johan Hovold2566fae62015-11-25 15:59:11 +010065struct gb_connection *gb_connection_create_static(struct gb_host_device *hd,
Johan Hovoldf7ee0812016-01-21 17:34:21 +010066 u16 hd_cport_id, gb_request_handler_t handler);
Johan Hovold59507e22016-01-21 17:34:12 +010067struct gb_connection *gb_connection_create_control(struct gb_interface *intf);
Johan Hovold96c2af52016-01-21 17:34:15 +010068struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
Johan Hovoldf7ee0812016-01-21 17:34:21 +010069 u16 cport_id, gb_request_handler_t handler);
Johan Hovold781ac8662016-05-11 10:17:57 +020070struct gb_connection *gb_connection_create_flags(struct gb_bundle *bundle,
Johan Hovoldcb033182016-03-03 13:34:36 +010071 u16 cport_id, gb_request_handler_t handler,
72 unsigned long flags);
Johan Hovold781ac8662016-05-11 10:17:57 +020073struct gb_connection *gb_connection_create_offloaded(struct gb_bundle *bundle,
74 u16 cport_id, unsigned long flags);
Alex Elderb05890d2014-10-02 12:30:01 -050075void gb_connection_destroy(struct gb_connection *connection);
Alex Elder574341c2014-10-16 06:35:35 -050076
Johan Hovold4ec15742015-11-25 15:59:13 +010077static inline bool gb_connection_is_static(struct gb_connection *connection)
78{
79 return !connection->intf;
80}
81
Johan Hovoldf7ee0812016-01-21 17:34:21 +010082int gb_connection_enable(struct gb_connection *connection);
83int gb_connection_enable_tx(struct gb_connection *connection);
Johan Hovoldbeb6b7f2016-01-19 12:51:08 +010084void gb_connection_disable_rx(struct gb_connection *connection);
Johan Hovold6d3d9502016-01-19 12:51:00 +010085void gb_connection_disable(struct gb_connection *connection);
Johan Hovold7aefe792016-05-27 17:26:22 +020086void gb_connection_disable_forced(struct gb_connection *connection);
Johan Hovold6d3d9502016-01-19 12:51:00 +010087
Johan Hovold55742d22016-05-27 17:26:40 +020088void gb_connection_mode_switch_prepare(struct gb_connection *connection);
89void gb_connection_mode_switch_complete(struct gb_connection *connection);
90
Johan Hovold25376362015-11-03 18:03:23 +010091void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
Alex Elder374e6a22014-11-17 18:08:37 -060092 u8 *data, size_t length);
Alex Eldereeeed422014-10-03 15:05:22 -050093
Bryan O'Donoghuee7e2efc2015-10-15 16:10:42 +010094void gb_connection_latency_tag_enable(struct gb_connection *connection);
95void gb_connection_latency_tag_disable(struct gb_connection *connection);
96
Johan Hovold64a6d132016-03-03 13:34:39 +010097static inline bool gb_connection_e2efc_enabled(struct gb_connection *connection)
98{
99 return !(connection->flags & GB_CONNECTION_FLAG_CSD);
100}
101
Johan Hovold0e9b41a2016-05-11 10:17:55 +0200102static inline bool
103gb_connection_flow_control_disabled(struct gb_connection *connection)
104{
105 return connection->flags & GB_CONNECTION_FLAG_NO_FLOWCTRL;
106}
107
Johan Hovoldca1f8f82016-05-11 10:17:56 +0200108static inline bool gb_connection_is_offloaded(struct gb_connection *connection)
109{
110 return connection->flags & GB_CONNECTION_FLAG_OFFLOADED;
111}
112
Johan Hovoldaca7aab2016-05-27 17:26:25 +0200113static inline bool gb_connection_is_control(struct gb_connection *connection)
114{
115 return connection->flags & GB_CONNECTION_FLAG_CONTROL;
116}
117
Greg Kroah-Hartman418f3da2016-03-22 14:30:16 -0400118static inline void *gb_connection_get_data(struct gb_connection *connection)
119{
120 return connection->private;
121}
122
123static inline void gb_connection_set_data(struct gb_connection *connection,
124 void *data)
125{
126 connection->private = data;
127}
128
Alex Elderc68adb22014-10-01 21:54:14 -0500129#endif /* __CONNECTION_H */