blob: cafcdd2a4fcf6d5efd80d3656d40e52724864a2e [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 */
27#define IPC_ROUTER_VERSION 1
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070028
29#define IPC_ROUTER_CLIENT_BCAST_ID 0xffffffff
30#define IPC_ROUTER_ADDRESS 0xfffffffe
31
32#define IPC_ROUTER_NID_LOCAL 1
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033
34#define IPC_ROUTER_CTRL_CMD_DATA 1
35#define IPC_ROUTER_CTRL_CMD_HELLO 2
36#define IPC_ROUTER_CTRL_CMD_BYE 3
37#define IPC_ROUTER_CTRL_CMD_NEW_SERVER 4
38#define IPC_ROUTER_CTRL_CMD_REMOVE_SERVER 5
39#define IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT 6
40#define IPC_ROUTER_CTRL_CMD_RESUME_TX 7
41#define IPC_ROUTER_CTRL_CMD_EXIT 8
42#define IPC_ROUTER_CTRL_CMD_PING 9
43
44#define IPC_ROUTER_DEFAULT_RX_QUOTA 5
45
46#define IPC_ROUTER_XPRT_EVENT_DATA 1
47#define IPC_ROUTER_XPRT_EVENT_OPEN 2
48#define IPC_ROUTER_XPRT_EVENT_CLOSE 3
49
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050#define IPC_ROUTER_INFINITY -1
Karthikeyan Ramasubramanianb7029232013-03-18 11:52:46 -060051#define DEFAULT_RCV_TIMEO 0
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052
53#define ALIGN_SIZE(x) ((4 - ((x) & 3)) & 3)
54
Karthikeyan Ramasubramanian5b502d3642012-09-23 22:23:36 -060055#define ALL_SERVICE 0xFFFFFFFF
56#define ALL_INSTANCE 0xFFFFFFFF
57
Karthikeyan Ramasubramanianf7a4b6e2013-01-16 09:00:28 -070058enum {
59 CLIENT_PORT,
60 SERVER_PORT,
61 CONTROL_PORT,
62 IRSC_PORT,
63};
64
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070065union rr_control_msg {
66 uint32_t cmd;
67 struct {
68 uint32_t cmd;
69 uint32_t service;
70 uint32_t instance;
71 uint32_t node_id;
72 uint32_t port_id;
73 } srv;
74 struct {
75 uint32_t cmd;
76 uint32_t node_id;
77 uint32_t port_id;
78 } cli;
79};
80
81struct rr_header {
82 uint32_t version;
83 uint32_t type;
84 uint32_t src_node_id;
85 uint32_t src_port_id;
86 uint32_t confirm_rx;
87 uint32_t size;
88 uint32_t dst_node_id;
89 uint32_t dst_port_id;
90};
91
92#define IPC_ROUTER_HDR_SIZE sizeof(struct rr_header)
93#define MAX_IPC_PKT_SIZE 66000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070094
95struct rr_packet {
96 struct list_head list;
97 struct sk_buff_head *pkt_fragment_q;
98 uint32_t length;
99};
100
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700101struct msm_ipc_sock {
102 struct sock sk;
103 struct msm_ipc_port *port;
Karthikeyan Ramasubramanian6b963bd2012-05-01 11:27:54 -0600104 void *default_pil;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700105};
106
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700107struct msm_ipc_router_xprt {
108 char *name;
109 uint32_t link_id;
110 void *priv;
111
Karthikeyan Ramasubramanian8cec5922012-02-16 17:41:58 -0700112 int (*read_avail)(struct msm_ipc_router_xprt *xprt);
113 int (*read)(void *data, uint32_t len,
114 struct msm_ipc_router_xprt *xprt);
115 int (*write_avail)(struct msm_ipc_router_xprt *xprt);
116 int (*write)(void *data, uint32_t len,
117 struct msm_ipc_router_xprt *xprt);
118 int (*close)(struct msm_ipc_router_xprt *xprt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700119};
120
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700121void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt,
122 unsigned event,
123 void *data);
124
125
126struct rr_packet *clone_pkt(struct rr_packet *pkt);
127void release_pkt(struct rr_packet *pkt);
128
129
130struct msm_ipc_port *msm_ipc_router_create_raw_port(void *endpoint,
Karthikeyan Ramasubramanianefc493b2012-07-12 10:25:49 -0600131 void (*notify)(unsigned event, void *priv),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700132 void *priv);
133int msm_ipc_router_send_to(struct msm_ipc_port *src,
134 struct sk_buff_head *data,
135 struct msm_ipc_addr *dest);
136int msm_ipc_router_read(struct msm_ipc_port *port_ptr,
137 struct sk_buff_head **data,
138 size_t buf_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700139int msm_ipc_router_bind_control_port(struct msm_ipc_port *port_ptr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700140
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141int msm_ipc_router_recv_from(struct msm_ipc_port *port_ptr,
142 struct sk_buff_head **data,
143 struct msm_ipc_addr *src_addr,
Karthikeyan Ramasubramanianefc493b2012-07-12 10:25:49 -0600144 long timeout);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700145int msm_ipc_router_register_server(struct msm_ipc_port *server_port,
146 struct msm_ipc_addr *name);
147int msm_ipc_router_unregister_server(struct msm_ipc_port *server_port);
148
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700149int msm_ipc_router_init_sockets(void);
150void msm_ipc_router_exit_sockets(void);
151
Karthikeyan Ramasubramanian5b502d3642012-09-23 22:23:36 -0600152void msm_ipc_sync_sec_rule(uint32_t service, uint32_t instance, void *rule);
153
154void msm_ipc_sync_default_sec_rule(void *rule);
155
Karthikeyan Ramasubramanian6b963bd2012-05-01 11:27:54 -0600156#if defined CONFIG_MSM_IPC_ROUTER_SMD_XPRT
157extern void *msm_ipc_load_default_node(void);
158
159extern void msm_ipc_unload_default_node(void *pil);
160#else
161static inline void *msm_ipc_load_default_node(void)
162{ return NULL; }
163
164static inline void msm_ipc_unload_default_node(void *pil) { }
165#endif
166
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700167#endif