blob: c18290f9b284a8df34392f12f32f619d67ce3e4f [file] [log] [blame]
Arun Kumar Neelakantam74ff8562017-05-26 17:57:52 +05301/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
Karthikeyan Ramasubramanian6a116d62016-09-16 16:05:32 -06002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _IPC_ROUTER_H
14#define _IPC_ROUTER_H
15
16#include <linux/types.h>
17#include <linux/socket.h>
18#include <linux/errno.h>
19#include <linux/mm.h>
20#include <linux/list.h>
21#include <linux/pm.h>
22#include <linux/msm_ipc.h>
23#include <linux/device.h>
24#include <linux/kref.h>
25
26/* Maximum Wakeup Source Name Size */
27#define MAX_WS_NAME_SZ 32
28
29#define IPC_RTR_ERR(buf, ...) \
30 pr_err("IPC_RTR: " buf, __VA_ARGS__)
31
32/**
33 * enum msm_ipc_router_event - Events that will be generated by IPC Router
34 */
35enum msm_ipc_router_event {
36 IPC_ROUTER_CTRL_CMD_DATA = 1,
37 IPC_ROUTER_CTRL_CMD_HELLO,
38 IPC_ROUTER_CTRL_CMD_BYE,
39 IPC_ROUTER_CTRL_CMD_NEW_SERVER,
40 IPC_ROUTER_CTRL_CMD_REMOVE_SERVER,
41 IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT,
42 IPC_ROUTER_CTRL_CMD_RESUME_TX,
43};
44
45/**
46 * rr_control_msg - Control message structure
47 * @cmd: Command identifier for HELLO message in Version 1.
48 * @hello: Message structure for HELLO message in Version 2.
49 * @srv: Message structure for NEW_SERVER/REMOVE_SERVER events.
50 * @cli: Message structure for REMOVE_CLIENT event.
51 */
52union rr_control_msg {
53 uint32_t cmd;
54 struct {
55 uint32_t cmd;
56 uint32_t checksum;
57 uint32_t versions;
58 uint32_t capability;
59 uint32_t reserved;
60 } hello;
61 struct {
62 uint32_t cmd;
63 uint32_t service;
64 uint32_t instance;
65 uint32_t node_id;
66 uint32_t port_id;
67 } srv;
68 struct {
69 uint32_t cmd;
70 uint32_t node_id;
71 uint32_t port_id;
72 } cli;
73};
74
75struct comm_mode_info {
76 int mode;
77 void *xprt_info;
78};
79
80enum ipc_rtr_af_event_type {
81 IPCRTR_AF_INIT = 1,
82 IPCRTR_AF_DEINIT,
83};
84
85/**
86 * msm_ipc_port - Definition of IPC Router port
87 * @list: List(local/control ports) in which this port is present.
88 * @ref: Reference count for this port.
89 * @this_port: Contains port's node_id and port_id information.
90 * @port_name: Contains service & instance info if the port hosts a service.
91 * @type: Type of the port - Client, Service, Control or Security Config.
92 * @flags: Flags to identify the port state.
93 * @port_lock_lhc3: Lock to protect access to the port information.
94 * @mode_info: Communication mode of the port owner.
95 * @port_rx_q: Receive queue where incoming messages are queued.
96 * @port_rx_q_lock_lhc3: Lock to protect access to the port's rx_q.
97 * @rx_ws_name: Name of the receive wakeup source.
98 * @port_rx_ws: Wakeup source to prevent suspend until the rx_q is empty.
99 * @port_rx_wait_q: Wait queue to wait for the incoming messages.
100 * @restart_state: Flag to hold the restart state information.
101 * @restart_lock: Lock to protect access to the restart_state.
102 * @restart_wait: Wait Queue to wait for any restart events.
103 * @endpoint: Contains the information related to user-space interface.
104 * @notify: Function to notify the incoming events on the port.
105 * @check_send_permissions: Function to check access control from this port.
106 * @num_tx: Number of packets transmitted.
107 * @num_rx: Number of packets received.
108 * @num_tx_bytes: Number of bytes transmitted.
109 * @num_rx_bytes: Number of bytes received.
110 * @priv: Private information registered by the port owner.
111 */
112struct msm_ipc_port {
113 struct list_head list;
114 struct kref ref;
115
116 struct msm_ipc_port_addr this_port;
117 struct msm_ipc_port_name port_name;
118 uint32_t type;
119 unsigned int flags;
120 struct mutex port_lock_lhc3;
121 struct comm_mode_info mode_info;
122
123 struct msm_ipc_port_addr dest_addr;
124 int conn_status;
125
126 struct list_head port_rx_q;
127 struct mutex port_rx_q_lock_lhc3;
128 char rx_ws_name[MAX_WS_NAME_SZ];
129 struct wakeup_source *port_rx_ws;
130 wait_queue_head_t port_rx_wait_q;
131 wait_queue_head_t port_tx_wait_q;
132
133 int restart_state;
134 spinlock_t restart_lock;
135 wait_queue_head_t restart_wait;
136
137 void *rport_info;
138 void *endpoint;
139 void (*notify)(unsigned int event, void *oob_data,
140 size_t oob_data_len, void *priv);
141 int (*check_send_permissions)(void *data);
142
143 uint32_t num_tx;
144 uint32_t num_rx;
145 unsigned long num_tx_bytes;
146 unsigned long num_rx_bytes;
Dhoat Harpal3ad5fe32017-06-19 21:26:13 +0530147 uint32_t last_served_svc_id;
Karthikeyan Ramasubramanian6a116d62016-09-16 16:05:32 -0600148 void *priv;
149};
150
151#ifdef CONFIG_IPC_ROUTER
152/**
153 * msm_ipc_router_create_port() - Create a IPC Router port/endpoint
154 * @notify: Callback function to notify any event on the port.
155 * @event: Event ID to be handled.
156 * @oob_data: Any out-of-band data associated with the event.
157 * @oob_data_len: Size of the out-of-band data, if valid.
158 * @priv: Private data registered during the port creation.
159 * @priv: Private info to be passed while the notification is generated.
160 *
161 * @return: Pointer to the port on success, NULL on error.
162 */
163struct msm_ipc_port *msm_ipc_router_create_port(
164 void (*notify)(unsigned int event, void *oob_data,
165 size_t oob_data_len, void *priv),
166 void *priv);
167
168/**
169 * msm_ipc_router_bind_control_port() - Bind a port as a control port
170 * @port_ptr: Port which needs to be marked as a control port.
171 *
172 * @return: 0 on success, standard Linux error codes on error.
173 */
174int msm_ipc_router_bind_control_port(struct msm_ipc_port *port_ptr);
175
176/**
177 * msm_ipc_router_lookup_server_name() - Resolve server address
178 * @srv_name: Name<service:instance> of the server to be resolved.
179 * @srv_info: Buffer to hold the resolved address.
180 * @num_entries_in_array: Number of server info the buffer can hold.
181 * @lookup_mask: Mask to specify the range of instances to be resolved.
182 *
183 * @return: Number of server addresses resolved on success, < 0 on error.
184 */
185int msm_ipc_router_lookup_server_name(struct msm_ipc_port_name *srv_name,
186 struct msm_ipc_server_info *srv_info,
187 int num_entries_in_array,
188 uint32_t lookup_mask);
189
190/**
191 * msm_ipc_router_send_msg() - Send a message/packet
192 * @src: Sender's address/port.
193 * @dest: Destination address.
194 * @data: Pointer to the data to be sent.
195 * @data_len: Length of the data to be sent.
196 *
197 * @return: 0 on success, < 0 on error.
198 */
199int msm_ipc_router_send_msg(struct msm_ipc_port *src,
200 struct msm_ipc_addr *dest,
201 void *data, unsigned int data_len);
202
203/**
204 * msm_ipc_router_get_curr_pkt_size() - Get the packet size of the first
205 * packet in the rx queue
206 * @port_ptr: Port which owns the rx queue.
207 *
208 * @return: Returns the size of the first packet, if available.
209 * 0 if no packets available, < 0 on error.
210 */
211int msm_ipc_router_get_curr_pkt_size(struct msm_ipc_port *port_ptr);
212
213/**
214 * msm_ipc_router_read_msg() - Read a message/packet
215 * @port_ptr: Receiver's port/address.
216 * @data: Pointer containing the address of the received data.
217 * @src: Address of the sender/source.
218 * @len: Length of the data being read.
219 *
220 * @return: 0 on success, < 0 on error.
221 */
222int msm_ipc_router_read_msg(struct msm_ipc_port *port_ptr,
223 struct msm_ipc_addr *src,
224 unsigned char **data,
225 unsigned int *len);
226
227/**
228 * msm_ipc_router_close_port() - Close the port
229 * @port_ptr: Pointer to the port to be closed.
230 *
231 * @return: 0 on success, < 0 on error.
232 */
233int msm_ipc_router_close_port(struct msm_ipc_port *port_ptr);
234
235/**
236 * msm_ipc_router_register_server() - Register a service on a port
237 * @server_port: IPC Router port with which a service is registered.
238 * @name: Service name <service_id:instance_id> that gets registered.
239 *
240 * @return: 0 on success, standard Linux error codes on error.
241 */
242int msm_ipc_router_register_server(struct msm_ipc_port *server_port,
243 struct msm_ipc_addr *name);
244
245/**
246 * msm_ipc_router_unregister_server() - Unregister a service from a port
247 * @server_port: Port with with a service is already registered.
248 *
249 * @return: 0 on success, standard Linux error codes on error.
250 */
251int msm_ipc_router_unregister_server(struct msm_ipc_port *server_port);
252
253/**
254 * register_ipcrtr_af_init_notifier() - Register for ipc router socket
255 * address family initialization callback
256 * @nb: Notifier block which will be notified once address family is
257 * initialized.
258 *
259 * Return: 0 on success, standard error code otherwise.
260 */
261int register_ipcrtr_af_init_notifier(struct notifier_block *nb);
262
263/**
264 * unregister_ipcrtr_af_init_notifier() - Unregister for ipc router socket
265 * address family initialization callback
266 * @nb: Notifier block which will be notified once address family is
267 * initialized.
268 *
269 * Return: 0 on success, standard error code otherwise.
270 */
271int unregister_ipcrtr_af_init_notifier(struct notifier_block *nb);
272
Arun Kumar Neelakantam74ff8562017-05-26 17:57:52 +0530273/**
274 * msm_ipc_router_set_ws_allowed() - To Enable/disable the wakeup source allowed
275 * flag
276 * @flag: Flag to set/clear the wakeup soruce allowed
277 *
278 */
279void msm_ipc_router_set_ws_allowed(bool flag);
280
Karthikeyan Ramasubramanian6a116d62016-09-16 16:05:32 -0600281#else
282
283struct msm_ipc_port *msm_ipc_router_create_port(
284 void (*notify)(unsigned int event, void *oob_data,
285 size_t oob_data_len, void *priv),
286 void *priv)
287{
288 return NULL;
289}
290
291static inline int msm_ipc_router_bind_control_port(
292 struct msm_ipc_port *port_ptr)
293{
294 return -ENODEV;
295}
296
297int msm_ipc_router_lookup_server_name(struct msm_ipc_port_name *srv_name,
298 struct msm_ipc_server_info *srv_info,
299 int num_entries_in_array,
300 uint32_t lookup_mask)
301{
302 return -ENODEV;
303}
304
305int msm_ipc_router_send_msg(struct msm_ipc_port *src,
306 struct msm_ipc_addr *dest,
307 void *data, unsigned int data_len)
308{
309 return -ENODEV;
310}
311
312int msm_ipc_router_get_curr_pkt_size(struct msm_ipc_port *port_ptr)
313{
314 return -ENODEV;
315}
316
317int msm_ipc_router_read_msg(struct msm_ipc_port *port_ptr,
318 struct msm_ipc_addr *src,
319 unsigned char **data,
320 unsigned int *len)
321{
322 return -ENODEV;
323}
324
325int msm_ipc_router_close_port(struct msm_ipc_port *port_ptr)
326{
327 return -ENODEV;
328}
329
330static inline int msm_ipc_router_register_server(
331 struct msm_ipc_port *server_port,
332 struct msm_ipc_addr *name)
333{
334 return -ENODEV;
335}
336
337static inline int msm_ipc_router_unregister_server(
338 struct msm_ipc_port *server_port)
339{
340 return -ENODEV;
341}
342
343int register_ipcrtr_af_init_notifier(struct notifier_block *nb)
344{
345 return -ENODEV;
346}
347
348int unregister_ipcrtr_af_init_notifier(struct notifier_block *nb)
349{
350 return -ENODEV;
351}
352
Arun Kumar Neelakantam74ff8562017-05-26 17:57:52 +0530353void msm_ipc_router_set_ws_allowed(bool flag) { }
354
Karthikeyan Ramasubramanian6a116d62016-09-16 16:05:32 -0600355#endif
356
357#endif