blob: 8ffd66166a285cbb6ba3f9a7821cc8df017865cf [file] [log] [blame]
Karthikeyan Ramasubramanianf7a4b6e2013-01-16 09:00:28 -07001/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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 _ARCH_ARM_MACH_MSM_IPC_ROUTER_H
14#define _ARCH_ARM_MACH_MSM_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>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070021#include <linux/platform_device.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070022#include <linux/msm_ipc.h>
23
24#include <net/sock.h>
25
26/* definitions for the R2R wire protcol */
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -060027#define IPC_ROUTER_V1 1
28/*
29 * Ambiguous definition but will enable multiplexing IPC_ROUTER_V2 packets
30 * with an existing alternate transport in user-space, if needed.
31 */
32#define IPC_ROUTER_V2 3
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -060034#define IPC_ROUTER_ADDRESS 0x0000FFFF
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035
36#define IPC_ROUTER_NID_LOCAL 1
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -060037#define MAX_IPC_PKT_SIZE 66000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038
39#define IPC_ROUTER_CTRL_CMD_DATA 1
40#define IPC_ROUTER_CTRL_CMD_HELLO 2
41#define IPC_ROUTER_CTRL_CMD_BYE 3
42#define IPC_ROUTER_CTRL_CMD_NEW_SERVER 4
43#define IPC_ROUTER_CTRL_CMD_REMOVE_SERVER 5
44#define IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT 6
45#define IPC_ROUTER_CTRL_CMD_RESUME_TX 7
46#define IPC_ROUTER_CTRL_CMD_EXIT 8
47#define IPC_ROUTER_CTRL_CMD_PING 9
48
49#define IPC_ROUTER_DEFAULT_RX_QUOTA 5
50
51#define IPC_ROUTER_XPRT_EVENT_DATA 1
52#define IPC_ROUTER_XPRT_EVENT_OPEN 2
53#define IPC_ROUTER_XPRT_EVENT_CLOSE 3
54
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070055#define IPC_ROUTER_INFINITY -1
Karthikeyan Ramasubramanianb7029232013-03-18 11:52:46 -060056#define DEFAULT_RCV_TIMEO 0
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057
58#define ALIGN_SIZE(x) ((4 - ((x) & 3)) & 3)
59
Karthikeyan Ramasubramanian5b502d3642012-09-23 22:23:36 -060060#define ALL_SERVICE 0xFFFFFFFF
61#define ALL_INSTANCE 0xFFFFFFFF
62
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -060063#define CONTROL_FLAG_CONFIRM_RX 0x1
64#define CONTROL_FLAG_OPT_HDR 0x2
65
66#define FRAG_PKT_WRITE_ENABLE 0x1
67
Karthikeyan Ramasubramanianf7a4b6e2013-01-16 09:00:28 -070068enum {
69 CLIENT_PORT,
70 SERVER_PORT,
71 CONTROL_PORT,
72 IRSC_PORT,
73};
74
Karthikeyan Ramasubramanian96cced72013-05-02 17:25:54 -060075enum {
76 NULL_MODE,
77 SINGLE_LINK_MODE,
78 MULTI_LINK_MODE,
79};
80
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -060081/**
82 * rr_control_msg - Control message structure
83 * @cmd: Command identifier for HELLO message in Version 1.
84 * @hello: Message structure for HELLO message in Version 2.
85 * @srv: Message structure for NEW_SERVER/REMOVE_SERVER events.
86 * @cli: Message structure for REMOVE_CLIENT event.
87 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070088union rr_control_msg {
89 uint32_t cmd;
90 struct {
91 uint32_t cmd;
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -060092 uint32_t magic;
93 uint32_t capability;
94 } hello;
95 struct {
96 uint32_t cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070097 uint32_t service;
98 uint32_t instance;
99 uint32_t node_id;
100 uint32_t port_id;
101 } srv;
102 struct {
103 uint32_t cmd;
104 uint32_t node_id;
105 uint32_t port_id;
106 } cli;
107};
108
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -0600109/**
110 * rr_header_v1 - IPC Router header version 1
111 * @version: Version information.
112 * @type: IPC Router Message Type.
113 * @src_node_id: Source Node ID of the message.
114 * @src_port_id: Source Port ID of the message.
115 * @control_flag: Flag to indicate flow control.
116 * @size: Size of the IPC Router payload.
117 * @dst_node_id: Destination Node ID of the message.
118 * @dst_port_id: Destination Port ID of the message.
119 */
120struct rr_header_v1 {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700121 uint32_t version;
122 uint32_t type;
123 uint32_t src_node_id;
124 uint32_t src_port_id;
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -0600125 uint32_t control_flag;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700126 uint32_t size;
127 uint32_t dst_node_id;
128 uint32_t dst_port_id;
129};
130
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -0600131/**
132 * rr_header_v2 - IPC Router header version 2
133 * @version: Version information.
134 * @type: IPC Router Message Type.
135 * @control_flag: Flags to indicate flow control, optional header etc.
136 * @size: Size of the IPC Router payload.
137 * @src_node_id: Source Node ID of the message.
138 * @src_port_id: Source Port ID of the message.
139 * @dst_node_id: Destination Node ID of the message.
140 * @dst_port_id: Destination Port ID of the message.
141 */
142struct rr_header_v2 {
143 uint8_t version;
144 uint8_t type;
145 uint16_t control_flag;
146 uint32_t size;
147 uint16_t src_node_id;
148 uint16_t src_port_id;
149 uint16_t dst_node_id;
150 uint16_t dst_port_id;
151} __attribute__((__packed__));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700152
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -0600153union rr_header {
154 struct rr_header_v1 hdr_v1;
155 struct rr_header_v2 hdr_v2;
156};
157
158#define IPC_ROUTER_HDR_SIZE sizeof(union rr_header)
159
160/**
161 * rr_packet - Router to Router packet structure
162 * @list: Pointer to prev & next packets in a port's rx list.
163 * @hdr: Header information extracted from or prepended to a packet.
164 * @pkt_fragment_q: Queue of SKBs containing payload.
165 * @length: Length of data in the chain of SKBs
166 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700167struct rr_packet {
168 struct list_head list;
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -0600169 struct rr_header_v1 hdr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700170 struct sk_buff_head *pkt_fragment_q;
171 uint32_t length;
172};
173
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174struct msm_ipc_sock {
175 struct sock sk;
176 struct msm_ipc_port *port;
Karthikeyan Ramasubramanian88f02e52013-06-03 12:05:50 -0600177 void *default_pil;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178};
179
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -0600180/**
181 * msm_ipc_router_xprt - Structure to hold XPRT specific information
182 * @name: Name of the XPRT.
183 * @link_id: Network cluster ID to which the XPRT belongs to.
184 * @priv: XPRT's private data.
185 * @get_version: Method to get header version supported by the XPRT.
186 * @get_option: Method to get XPRT specific options.
187 * @read_avail: Method to get data size available to be read from the XPRT.
188 * @read: Method to read data from the XPRT.
189 * @write_avail: Method to get write space available in the XPRT.
190 * @write: Method to write data to the XPRT.
191 * @close: Method to close the XPRT.
192 * @sft_close_done: Method to indicate to the XPRT that handling of reset
193 * event is complete.
194 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700195struct msm_ipc_router_xprt {
196 char *name;
197 uint32_t link_id;
198 void *priv;
199
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -0600200 int (*get_version)(struct msm_ipc_router_xprt *xprt);
201 int (*get_option)(struct msm_ipc_router_xprt *xprt);
Karthikeyan Ramasubramanian8cec5922012-02-16 17:41:58 -0700202 int (*read_avail)(struct msm_ipc_router_xprt *xprt);
203 int (*read)(void *data, uint32_t len,
204 struct msm_ipc_router_xprt *xprt);
205 int (*write_avail)(struct msm_ipc_router_xprt *xprt);
206 int (*write)(void *data, uint32_t len,
207 struct msm_ipc_router_xprt *xprt);
208 int (*close)(struct msm_ipc_router_xprt *xprt);
Karthikeyan Ramasubramaniane6ef0a22013-06-12 11:49:26 -0600209 void (*sft_close_done)(struct msm_ipc_router_xprt *xprt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700210};
211
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700212void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt,
213 unsigned event,
214 void *data);
215
216
217struct rr_packet *clone_pkt(struct rr_packet *pkt);
218void release_pkt(struct rr_packet *pkt);
219
220
221struct msm_ipc_port *msm_ipc_router_create_raw_port(void *endpoint,
Karthikeyan Ramasubramanianefc493b2012-07-12 10:25:49 -0600222 void (*notify)(unsigned event, void *priv),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700223 void *priv);
224int msm_ipc_router_send_to(struct msm_ipc_port *src,
225 struct sk_buff_head *data,
226 struct msm_ipc_addr *dest);
227int msm_ipc_router_read(struct msm_ipc_port *port_ptr,
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -0600228 struct rr_packet **pkt,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700229 size_t buf_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700230int msm_ipc_router_bind_control_port(struct msm_ipc_port *port_ptr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700231
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700232int msm_ipc_router_recv_from(struct msm_ipc_port *port_ptr,
Karthikeyan Ramasubramanian7edb6802013-04-16 23:12:44 -0600233 struct rr_packet **pkt,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700234 struct msm_ipc_addr *src_addr,
Karthikeyan Ramasubramanianefc493b2012-07-12 10:25:49 -0600235 long timeout);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700236int msm_ipc_router_register_server(struct msm_ipc_port *server_port,
237 struct msm_ipc_addr *name);
238int msm_ipc_router_unregister_server(struct msm_ipc_port *server_port);
239
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700240int msm_ipc_router_init_sockets(void);
241void msm_ipc_router_exit_sockets(void);
242
Karthikeyan Ramasubramanian5b502d3642012-09-23 22:23:36 -0600243void msm_ipc_sync_sec_rule(uint32_t service, uint32_t instance, void *rule);
244
245void msm_ipc_sync_default_sec_rule(void *rule);
246
Arun Kumar Neelakantam0af96762013-06-21 17:57:18 +0530247int msm_ipc_router_rx_data_wait(struct msm_ipc_port *port_ptr, long timeout);
248
Karthikeyan Ramasubramanian88f02e52013-06-03 12:05:50 -0600249#if defined CONFIG_MSM_IPC_ROUTER_SMD_XPRT
250extern void *msm_ipc_load_default_node(void);
251
252extern void msm_ipc_unload_default_node(void *pil);
253#else
254static inline void *msm_ipc_load_default_node(void)
255{ return NULL; }
256
257static inline void msm_ipc_unload_default_node(void *pil) { }
258#endif
259
Zaheerulla Meer74425252013-08-20 12:02:31 +0530260void msm_ipc_router_free_skb(struct sk_buff_head *skb_head);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700261#endif