blob: 07bc5e01043a8efc56e5afd55cf793b25735d0b2 [file] [log] [blame]
Karthikeyan Ramasubramanian8cec5922012-02-16 17:41:58 -07001/* Copyright (c) 2011-2012, Code Aurora Forum. 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>
21#include <linux/cdev.h>
22#include <linux/platform_device.h>
23#include <linux/wakelock.h>
24#include <linux/msm_ipc.h>
25
26#include <net/sock.h>
27
28/* definitions for the R2R wire protcol */
29#define IPC_ROUTER_VERSION 1
30#define IPC_ROUTER_PROCESSORS_MAX 4
31
32#define IPC_ROUTER_CLIENT_BCAST_ID 0xffffffff
33#define IPC_ROUTER_ADDRESS 0xfffffffe
34
35#define IPC_ROUTER_NID_LOCAL 1
36#define IPC_ROUTER_NID_REMOTE 0
37
38#define IPC_ROUTER_CTRL_CMD_DATA 1
39#define IPC_ROUTER_CTRL_CMD_HELLO 2
40#define IPC_ROUTER_CTRL_CMD_BYE 3
41#define IPC_ROUTER_CTRL_CMD_NEW_SERVER 4
42#define IPC_ROUTER_CTRL_CMD_REMOVE_SERVER 5
43#define IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT 6
44#define IPC_ROUTER_CTRL_CMD_RESUME_TX 7
45#define IPC_ROUTER_CTRL_CMD_EXIT 8
46#define IPC_ROUTER_CTRL_CMD_PING 9
47
48#define IPC_ROUTER_DEFAULT_RX_QUOTA 5
49
50#define IPC_ROUTER_XPRT_EVENT_DATA 1
51#define IPC_ROUTER_XPRT_EVENT_OPEN 2
52#define IPC_ROUTER_XPRT_EVENT_CLOSE 3
53
54#define NUM_NODES 2
55
56#define IPC_ROUTER_INFINITY -1
57#define DEFAULT_RCV_TIMEO IPC_ROUTER_INFINITY
58
59#define ALIGN_SIZE(x) ((4 - ((x) & 3)) & 3)
60
61enum {
62 MSM_IPC_ROUTER_READ_CB = 0,
63 MSM_IPC_ROUTER_WRITE_DONE,
64};
65
66union rr_control_msg {
67 uint32_t cmd;
68 struct {
69 uint32_t cmd;
70 uint32_t service;
71 uint32_t instance;
72 uint32_t node_id;
73 uint32_t port_id;
74 } srv;
75 struct {
76 uint32_t cmd;
77 uint32_t node_id;
78 uint32_t port_id;
79 } cli;
80};
81
82struct rr_header {
83 uint32_t version;
84 uint32_t type;
85 uint32_t src_node_id;
86 uint32_t src_port_id;
87 uint32_t confirm_rx;
88 uint32_t size;
89 uint32_t dst_node_id;
90 uint32_t dst_port_id;
91};
92
93#define IPC_ROUTER_HDR_SIZE sizeof(struct rr_header)
94#define MAX_IPC_PKT_SIZE 66000
95/* internals */
96
97#define IPC_ROUTER_MAX_REMOTE_SERVERS 100
Karthikeyan Ramasubramanianb4aeeb92012-03-13 12:31:43 -060098#define MAX_WAKELOCK_NAME_SZ 32
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070099
100struct rr_packet {
101 struct list_head list;
102 struct sk_buff_head *pkt_fragment_q;
103 uint32_t length;
104};
105
106struct msm_ipc_port {
107 struct list_head list;
108
109 struct msm_ipc_port_addr this_port;
110 struct msm_ipc_port_name port_name;
111 uint32_t type;
112 unsigned flags;
113 spinlock_t port_lock;
114
115 struct list_head incomplete;
116 struct mutex incomplete_lock;
117
118 struct list_head port_rx_q;
119 struct mutex port_rx_q_lock;
Karthikeyan Ramasubramanianb4aeeb92012-03-13 12:31:43 -0600120 char rx_wakelock_name[MAX_WAKELOCK_NAME_SZ];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700121 struct wake_lock port_rx_wake_lock;
122 wait_queue_head_t port_rx_wait_q;
123
124 int restart_state;
125 spinlock_t restart_lock;
126 wait_queue_head_t restart_wait;
127
128 void *endpoint;
129 void (*notify)(unsigned event, void *data, void *addr, void *priv);
130
131 uint32_t num_tx;
132 uint32_t num_rx;
133 unsigned long num_tx_bytes;
134 unsigned long num_rx_bytes;
135 void *priv;
136};
137
138struct msm_ipc_sock {
139 struct sock sk;
140 struct msm_ipc_port *port;
Karthikeyan Ramasubramanian6b963bd2012-05-01 11:27:54 -0600141 void *default_pil;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700142};
143
144enum write_data_type {
145 HEADER = 1,
146 PACKMARK,
147 PAYLOAD,
148};
149
150struct msm_ipc_router_xprt {
151 char *name;
152 uint32_t link_id;
153 void *priv;
154
Karthikeyan Ramasubramanian8cec5922012-02-16 17:41:58 -0700155 int (*read_avail)(struct msm_ipc_router_xprt *xprt);
156 int (*read)(void *data, uint32_t len,
157 struct msm_ipc_router_xprt *xprt);
158 int (*write_avail)(struct msm_ipc_router_xprt *xprt);
159 int (*write)(void *data, uint32_t len,
160 struct msm_ipc_router_xprt *xprt);
161 int (*close)(struct msm_ipc_router_xprt *xprt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700162};
163
164extern struct completion msm_ipc_remote_router_up;
165
166void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt,
167 unsigned event,
168 void *data);
169
170
171struct rr_packet *clone_pkt(struct rr_packet *pkt);
172void release_pkt(struct rr_packet *pkt);
173
174
175struct msm_ipc_port *msm_ipc_router_create_raw_port(void *endpoint,
176 void (*notify)(unsigned event, void *data,
177 void *addr, void *priv),
178 void *priv);
179int msm_ipc_router_send_to(struct msm_ipc_port *src,
180 struct sk_buff_head *data,
181 struct msm_ipc_addr *dest);
182int msm_ipc_router_read(struct msm_ipc_port *port_ptr,
183 struct sk_buff_head **data,
184 size_t buf_len);
185int msm_ipc_router_get_curr_pkt_size(struct msm_ipc_port *port_ptr);
186int msm_ipc_router_bind_control_port(struct msm_ipc_port *port_ptr);
187int msm_ipc_router_lookup_server_name(struct msm_ipc_port_name *srv_name,
Karthikeyan Ramasubramaniandfde01b2012-06-12 14:25:13 -0600188 struct msm_ipc_server_info *srv_info,
Karthikeyan Ramasubramaniancc450c92011-07-27 14:38:15 -0600189 int num_entries_in_array,
190 uint32_t lookup_mask);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700191int msm_ipc_router_close_port(struct msm_ipc_port *port_ptr);
192
193struct msm_ipc_port *msm_ipc_router_create_port(
194 void (*notify)(unsigned event, void *data,
195 void *addr, void *priv),
196 void *priv);
197int msm_ipc_router_recv_from(struct msm_ipc_port *port_ptr,
198 struct sk_buff_head **data,
199 struct msm_ipc_addr *src_addr,
200 unsigned long timeout);
201int msm_ipc_router_register_server(struct msm_ipc_port *server_port,
202 struct msm_ipc_addr *name);
203int msm_ipc_router_unregister_server(struct msm_ipc_port *server_port);
204
205
206int msm_ipc_router_init_sockets(void);
207void msm_ipc_router_exit_sockets(void);
208
Karthikeyan Ramasubramanian6b963bd2012-05-01 11:27:54 -0600209#if defined CONFIG_MSM_IPC_ROUTER_SMD_XPRT
210extern void *msm_ipc_load_default_node(void);
211
212extern void msm_ipc_unload_default_node(void *pil);
213#else
214static inline void *msm_ipc_load_default_node(void)
215{ return NULL; }
216
217static inline void msm_ipc_unload_default_node(void *pil) { }
218#endif
219
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700220#endif