blob: 8813f54eab9209001c93d5f5013586e9c551f276 [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
Alex Elder36561f22014-10-22 02:04:30 -050016enum gb_connection_state {
17 GB_CONNECTION_STATE_INVALID = 0,
18 GB_CONNECTION_STATE_DISABLED = 1,
Johan Hovold570dfa72016-01-19 12:51:07 +010019 GB_CONNECTION_STATE_ENABLED_TX = 2,
20 GB_CONNECTION_STATE_ENABLED = 3,
Alex Elder36561f22014-10-22 02:04:30 -050021};
22
Johan Hovoldbfa9a5e2016-01-19 12:51:02 +010023struct gb_operation;
24
25typedef int (*gb_request_handler_t)(struct gb_operation *);
26
Alex Elderc68adb22014-10-01 21:54:14 -050027struct gb_connection {
Johan Hovold25376362015-11-03 18:03:23 +010028 struct gb_host_device *hd;
Johan Hovold2566fae2015-11-25 15:59:11 +010029 struct gb_interface *intf;
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -050030 struct gb_bundle *bundle;
Greg Kroah-Hartmanb750fa32015-10-16 16:56:38 -070031 struct kref kref;
Alex Eldercd345072014-10-02 12:30:05 -050032 u16 hd_cport_id;
Viresh Kumard7353ce2015-06-04 10:18:01 +053033 u16 intf_cport_id;
Alex Elderc68adb22014-10-01 21:54:14 -050034
Alex Elder2c43ce42014-11-17 08:08:44 -060035 struct list_head hd_links;
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -050036 struct list_head bundle_links;
Alex Elder4ccb6b72014-10-28 19:36:00 -050037
Johan Hovoldbfa9a5e2016-01-19 12:51:02 +010038 gb_request_handler_t handler;
39
Alex Elder4ccb6b72014-10-28 19:36:00 -050040 struct gb_protocol *protocol;
Greg Kroah-Hartmanfb69cb52014-12-23 15:16:53 -080041 u8 protocol_id;
42 u8 major;
43 u8 minor;
Viresh Kumard653f4b12015-08-11 07:35:58 +053044 u8 module_major;
45 u8 module_minor;
Alex Elder7fba0072014-10-28 19:35:59 -050046
Johan Hovold23268782016-01-19 12:51:06 +010047 struct mutex mutex;
Johan Hovoldcad09a82015-07-14 15:43:30 +020048 spinlock_t lock;
Alex Elder36561f22014-10-22 02:04:30 -050049 enum gb_connection_state state;
Johan Hovold008974c2015-07-14 15:43:31 +020050 struct list_head operations;
Alex Eldere88afa52014-10-01 21:54:15 -050051
Johan Hovold729b2602015-11-25 15:59:14 +010052 char name[16];
Johan Hovold5a5bc352015-07-23 10:50:02 +020053 struct workqueue_struct *wq;
54
Alex Elder4afb7fd2014-12-03 08:35:08 -060055 atomic_t op_cycle;
Alex Elder8a306722014-10-03 15:05:21 -050056
57 void *private;
Alex Elderc68adb22014-10-01 21:54:14 -050058};
59
Johan Hovold2566fae2015-11-25 15:59:11 +010060struct gb_connection *gb_connection_create_static(struct gb_host_device *hd,
61 u16 hd_cport_id, u8 protocol_id);
62struct gb_connection *gb_connection_create_dynamic(struct gb_interface *intf,
63 struct gb_bundle *bundle, u16 cport_id,
64 u8 protocol_id);
Alex Elderb05890d2014-10-02 12:30:01 -050065void gb_connection_destroy(struct gb_connection *connection);
Alex Elder574341c2014-10-16 06:35:35 -050066
Johan Hovold4ec15742015-11-25 15:59:13 +010067static inline bool gb_connection_is_static(struct gb_connection *connection)
68{
69 return !connection->intf;
70}
71
Johan Hovoldbfa9a5e2016-01-19 12:51:02 +010072int gb_connection_enable(struct gb_connection *connection,
73 gb_request_handler_t handler);
Johan Hovold570dfa72016-01-19 12:51:07 +010074static inline int gb_connection_enable_tx(struct gb_connection *connection)
75{
76 return gb_connection_enable(connection, NULL);
77}
Johan Hovoldbeb6b7f2016-01-19 12:51:08 +010078void gb_connection_disable_rx(struct gb_connection *connection);
Johan Hovold6d3d9502016-01-19 12:51:00 +010079void gb_connection_disable(struct gb_connection *connection);
80
81int gb_connection_legacy_init(struct gb_connection *connection);
82void gb_connection_legacy_exit(struct gb_connection *connection);
Johan Hovold0bf1f242015-12-07 15:05:34 +010083
Johan Hovold25376362015-11-03 18:03:23 +010084void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
Alex Elder374e6a22014-11-17 18:08:37 -060085 u8 *data, size_t length);
Alex Eldereeeed422014-10-03 15:05:22 -050086
Bryan O'Donoghuee7e2efc2015-10-15 16:10:42 +010087void gb_connection_latency_tag_enable(struct gb_connection *connection);
88void gb_connection_latency_tag_disable(struct gb_connection *connection);
89
Alex Elderc68adb22014-10-01 21:54:14 -050090#endif /* __CONNECTION_H */