blob: 39038f277d839f1a485f477cf2c6c44aa8ff15ab [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>
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
51#define DEFAULT_RCV_TIMEO IPC_ROUTER_INFINITY
52
53#define ALIGN_SIZE(x) ((4 - ((x) & 3)) & 3)
54
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070055union rr_control_msg {
56 uint32_t cmd;
57 struct {
58 uint32_t cmd;
59 uint32_t service;
60 uint32_t instance;
61 uint32_t node_id;
62 uint32_t port_id;
63 } srv;
64 struct {
65 uint32_t cmd;
66 uint32_t node_id;
67 uint32_t port_id;
68 } cli;
69};
70
71struct rr_header {
72 uint32_t version;
73 uint32_t type;
74 uint32_t src_node_id;
75 uint32_t src_port_id;
76 uint32_t confirm_rx;
77 uint32_t size;
78 uint32_t dst_node_id;
79 uint32_t dst_port_id;
80};
81
82#define IPC_ROUTER_HDR_SIZE sizeof(struct rr_header)
83#define MAX_IPC_PKT_SIZE 66000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070084
85struct rr_packet {
86 struct list_head list;
87 struct sk_buff_head *pkt_fragment_q;
88 uint32_t length;
89};
90
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091struct msm_ipc_sock {
92 struct sock sk;
93 struct msm_ipc_port *port;
Karthikeyan Ramasubramanian6b963bd2012-05-01 11:27:54 -060094 void *default_pil;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070095};
96
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070097struct msm_ipc_router_xprt {
98 char *name;
99 uint32_t link_id;
100 void *priv;
101
Karthikeyan Ramasubramanian8cec5922012-02-16 17:41:58 -0700102 int (*read_avail)(struct msm_ipc_router_xprt *xprt);
103 int (*read)(void *data, uint32_t len,
104 struct msm_ipc_router_xprt *xprt);
105 int (*write_avail)(struct msm_ipc_router_xprt *xprt);
106 int (*write)(void *data, uint32_t len,
107 struct msm_ipc_router_xprt *xprt);
108 int (*close)(struct msm_ipc_router_xprt *xprt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700109};
110
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700111void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt,
112 unsigned event,
113 void *data);
114
115
116struct rr_packet *clone_pkt(struct rr_packet *pkt);
117void release_pkt(struct rr_packet *pkt);
118
119
120struct msm_ipc_port *msm_ipc_router_create_raw_port(void *endpoint,
Karthikeyan Ramasubramanianefc493b2012-07-12 10:25:49 -0600121 void (*notify)(unsigned event, void *priv),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700122 void *priv);
123int msm_ipc_router_send_to(struct msm_ipc_port *src,
124 struct sk_buff_head *data,
125 struct msm_ipc_addr *dest);
126int msm_ipc_router_read(struct msm_ipc_port *port_ptr,
127 struct sk_buff_head **data,
128 size_t buf_len);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129int msm_ipc_router_bind_control_port(struct msm_ipc_port *port_ptr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700130
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131int msm_ipc_router_recv_from(struct msm_ipc_port *port_ptr,
132 struct sk_buff_head **data,
133 struct msm_ipc_addr *src_addr,
Karthikeyan Ramasubramanianefc493b2012-07-12 10:25:49 -0600134 long timeout);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700135int msm_ipc_router_register_server(struct msm_ipc_port *server_port,
136 struct msm_ipc_addr *name);
137int msm_ipc_router_unregister_server(struct msm_ipc_port *server_port);
138
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700139int msm_ipc_router_init_sockets(void);
140void msm_ipc_router_exit_sockets(void);
141
Karthikeyan Ramasubramanian6b963bd2012-05-01 11:27:54 -0600142#if defined CONFIG_MSM_IPC_ROUTER_SMD_XPRT
143extern void *msm_ipc_load_default_node(void);
144
145extern void msm_ipc_unload_default_node(void *pil);
146#else
147static inline void *msm_ipc_load_default_node(void)
148{ return NULL; }
149
150static inline void msm_ipc_unload_default_node(void *pil) { }
151#endif
152
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700153#endif