blob: b125185448898938f6373e50d98f058b03de11e0 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
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
98
99struct rr_packet {
100 struct list_head list;
101 struct sk_buff_head *pkt_fragment_q;
102 uint32_t length;
103};
104
105struct msm_ipc_port {
106 struct list_head list;
107
108 struct msm_ipc_port_addr this_port;
109 struct msm_ipc_port_name port_name;
110 uint32_t type;
111 unsigned flags;
112 spinlock_t port_lock;
113
114 struct list_head incomplete;
115 struct mutex incomplete_lock;
116
117 struct list_head port_rx_q;
118 struct mutex port_rx_q_lock;
119 struct wake_lock port_rx_wake_lock;
120 wait_queue_head_t port_rx_wait_q;
121
122 int restart_state;
123 spinlock_t restart_lock;
124 wait_queue_head_t restart_wait;
125
126 void *endpoint;
127 void (*notify)(unsigned event, void *data, void *addr, void *priv);
128
129 uint32_t num_tx;
130 uint32_t num_rx;
131 unsigned long num_tx_bytes;
132 unsigned long num_rx_bytes;
133 void *priv;
134};
135
136struct msm_ipc_sock {
137 struct sock sk;
138 struct msm_ipc_port *port;
139 void *modem_pil;
140};
141
142enum write_data_type {
143 HEADER = 1,
144 PACKMARK,
145 PAYLOAD,
146};
147
148struct msm_ipc_router_xprt {
149 char *name;
150 uint32_t link_id;
151 void *priv;
152
153 int (*read_avail)(void);
154 int (*read)(void *data, uint32_t len);
155 int (*write_avail)(void);
156 int (*write)(void *data, uint32_t len, enum write_data_type type);
157 int (*close)(void);
158};
159
160extern struct completion msm_ipc_remote_router_up;
161
162void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt,
163 unsigned event,
164 void *data);
165
166
167struct rr_packet *clone_pkt(struct rr_packet *pkt);
168void release_pkt(struct rr_packet *pkt);
169
170
171struct msm_ipc_port *msm_ipc_router_create_raw_port(void *endpoint,
172 void (*notify)(unsigned event, void *data,
173 void *addr, void *priv),
174 void *priv);
175int msm_ipc_router_send_to(struct msm_ipc_port *src,
176 struct sk_buff_head *data,
177 struct msm_ipc_addr *dest);
178int msm_ipc_router_read(struct msm_ipc_port *port_ptr,
179 struct sk_buff_head **data,
180 size_t buf_len);
181int msm_ipc_router_get_curr_pkt_size(struct msm_ipc_port *port_ptr);
182int msm_ipc_router_bind_control_port(struct msm_ipc_port *port_ptr);
183int msm_ipc_router_lookup_server_name(struct msm_ipc_port_name *srv_name,
184 struct msm_ipc_port_addr *port_addr,
Karthikeyan Ramasubramaniancc450c92011-07-27 14:38:15 -0600185 int num_entries_in_array,
186 uint32_t lookup_mask);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187int msm_ipc_router_close_port(struct msm_ipc_port *port_ptr);
188
189struct msm_ipc_port *msm_ipc_router_create_port(
190 void (*notify)(unsigned event, void *data,
191 void *addr, void *priv),
192 void *priv);
193int msm_ipc_router_recv_from(struct msm_ipc_port *port_ptr,
194 struct sk_buff_head **data,
195 struct msm_ipc_addr *src_addr,
196 unsigned long timeout);
197int msm_ipc_router_register_server(struct msm_ipc_port *server_port,
198 struct msm_ipc_addr *name);
199int msm_ipc_router_unregister_server(struct msm_ipc_port *server_port);
200
201
202int msm_ipc_router_init_sockets(void);
203void msm_ipc_router_exit_sockets(void);
204
205#endif