summaryrefslogtreecommitdiff
path: root/drivers/staging/greybus/connection.h
blob: 4492d2f67ec4e49527866afad88eed0a0fceae3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Greybus connections
 *
 * Copyright 2014 Google Inc.
 *
 * Released under the GPLv2 only.
 */

#ifndef __CONNECTION_H
#define __CONNECTION_H

#include <linux/list.h>

#include "greybus.h"

enum gb_connection_state {
	GB_CONNECTION_STATE_INVALID	= 0,
	GB_CONNECTION_STATE_DISABLED	= 1,
	GB_CONNECTION_STATE_ENABLED	= 2,
	GB_CONNECTION_STATE_ERROR	= 3,
	GB_CONNECTION_STATE_DESTROYING	= 4,
};

struct gb_connection;
typedef int (*gb_connection_init_t)(struct gb_connection *);
typedef void (*gb_connection_exit_t)(struct gb_connection *);

struct gb_connection_handler {
	gb_connection_init_t	connection_init;
	gb_connection_exit_t	connection_exit;
};

struct gb_connection {
	struct greybus_host_device	*hd;
	struct gb_interface		*interface;
	struct device			dev;
	u16				hd_cport_id;
	u16				interface_cport_id;

	struct rb_node			hd_node;
	struct list_head		interface_links;
	enum greybus_protocol		protocol;
	enum gb_connection_state	state;

	struct list_head		operations;
	struct rb_root			pending;	/* awaiting reponse */
	atomic_t			op_cycle;
	struct delayed_work		timeout_work;

	struct gb_connection_handler	*handler;

	void				*private;
};
#define to_gb_connection(d) container_of(d, struct gb_connection, dev)

struct gb_connection *gb_connection_create(struct gb_interface *interface,
				u16 cport_id, enum greybus_protocol protocol);
void gb_connection_destroy(struct gb_connection *connection);

int gb_connection_init(struct gb_connection *connection);
void gb_connection_exit(struct gb_connection *connection);

struct gb_connection *gb_hd_connection_find(struct greybus_host_device *hd,
				u16 cport_id);

u16 gb_connection_operation_id(struct gb_connection *connection);

__printf(2, 3)
void gb_connection_err(struct gb_connection *connection, const char *fmt, ...);

#endif /* __CONNECTION_H */