aboutsummaryrefslogtreecommitdiff
path: root/include/vservices/protocol/serial/server.h
blob: 001fed5949af095d60b63d8f4f58d3e2def6fd9c (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Copyright (c) 2012-2018 General Dynamics
 * Copyright (c) 2014 Open Kernel Labs, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#if !defined(VSERVICES_SERVER_SERIAL)
#define VSERVICES_SERVER_SERIAL

struct vs_service_device;
struct vs_server_serial_state;

struct vs_server_serial {

	/*
	 * If set to false then the receive message handlers are run from
	 * workqueue context and are allowed to sleep. If set to true the
	 * message handlers are run from tasklet context and may not sleep.
	 */
	bool rx_atomic;

	/*
	 * If this is set to true along with rx_atomic, the driver is allowed
	 * to send messages from softirq contexts other than the receive
	 * message handlers, after calling vs_service_state_lock_bh. Otherwise,
	 * messages may only be sent from the receive message handlers, or
	 * from task context after calling vs_service_state_lock. This must
	 * not be set to true if rx_atomic is set to false.
	 */
	bool tx_atomic;

	/*
	 * These are the driver's recommended message quotas. They are used
	 * by the core service to select message quotas for services with no
	 * explicitly configured quotas.
	 */
	u32 in_quota_best;
	u32 out_quota_best;
    /** session setup **/
	struct vs_server_serial_state *(*alloc) (struct vs_service_device *
						 service);
	void (*release) (struct vs_server_serial_state * _state);

	struct vs_service_driver *driver;

/** Open, reopen, close and closed functions **/

	 vs_server_response_type_t(*open) (struct vs_server_serial_state *
					   _state);

	 vs_server_response_type_t(*reopen) (struct vs_server_serial_state *
					     _state);

	 vs_server_response_type_t(*close) (struct vs_server_serial_state *
					    _state);

	void (*closed) (struct vs_server_serial_state * _state);

/** Send/receive state callbacks **/
	int (*tx_ready) (struct vs_server_serial_state * _state);

	struct {
		int (*msg_msg) (struct vs_server_serial_state * _state,
				struct vs_pbuf b, struct vs_mbuf * _mbuf);

	} serial;
};

struct vs_server_serial_state {
	vservice_serial_protocol_state_t state;
	uint32_t packet_size;
	struct {
		uint32_t packet_size;
	} serial;
	struct vs_service_device *service;
	bool released;
};

/** Complete calls for server core functions **/
extern int vs_server_serial_open_complete(struct vs_server_serial_state *_state,
					  vs_server_response_type_t resp);

extern int vs_server_serial_close_complete(struct vs_server_serial_state
					   *_state,
					   vs_server_response_type_t resp);

extern int vs_server_serial_reopen_complete(struct vs_server_serial_state
					    *_state,
					    vs_server_response_type_t resp);

    /** interface serial **/
/* message msg */
extern struct vs_mbuf *vs_server_serial_serial_alloc_msg(struct
							 vs_server_serial_state
							 *_state,
							 struct vs_pbuf *b,
							 gfp_t flags);
extern int vs_server_serial_serial_getbufs_msg(struct vs_server_serial_state
					       *_state, struct vs_pbuf *b,
					       struct vs_mbuf *_mbuf);
extern int vs_server_serial_serial_free_msg(struct vs_server_serial_state
					    *_state, struct vs_pbuf *b,
					    struct vs_mbuf *_mbuf);
extern int vs_server_serial_serial_send_msg(struct vs_server_serial_state
					    *_state, struct vs_pbuf b,
					    struct vs_mbuf *_mbuf);

/** Module registration **/

struct module;

extern int __vservice_serial_server_register(struct vs_server_serial *server,
					     const char *name,
					     struct module *owner);

static inline int vservice_serial_server_register(struct vs_server_serial
						  *server, const char *name)
{
#ifdef MODULE
	extern struct module __this_module;
	struct module *this_module = &__this_module;
#else
	struct module *this_module = NULL;
#endif

	return __vservice_serial_server_register(server, name, this_module);
}

extern int vservice_serial_server_unregister(struct vs_server_serial *server);
#endif				/* ! VSERVICES_SERVER_SERIAL */