Karthikeyan Ramasubramanian | f7a4b6e | 2013-01-16 09:00:28 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 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> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 22 | #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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 28 | |
| 29 | #define IPC_ROUTER_CLIENT_BCAST_ID 0xffffffff |
| 30 | #define IPC_ROUTER_ADDRESS 0xfffffffe |
| 31 | |
| 32 | #define IPC_ROUTER_NID_LOCAL 1 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 33 | |
| 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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 50 | #define IPC_ROUTER_INFINITY -1 |
Karthikeyan Ramasubramanian | b702923 | 2013-03-18 11:52:46 -0600 | [diff] [blame] | 51 | #define DEFAULT_RCV_TIMEO 0 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 52 | |
| 53 | #define ALIGN_SIZE(x) ((4 - ((x) & 3)) & 3) |
| 54 | |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 55 | #define ALL_SERVICE 0xFFFFFFFF |
| 56 | #define ALL_INSTANCE 0xFFFFFFFF |
| 57 | |
Karthikeyan Ramasubramanian | f7a4b6e | 2013-01-16 09:00:28 -0700 | [diff] [blame] | 58 | enum { |
| 59 | CLIENT_PORT, |
| 60 | SERVER_PORT, |
| 61 | CONTROL_PORT, |
| 62 | IRSC_PORT, |
| 63 | }; |
| 64 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 65 | union 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 | |
| 81 | struct 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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 94 | |
| 95 | struct rr_packet { |
| 96 | struct list_head list; |
| 97 | struct sk_buff_head *pkt_fragment_q; |
| 98 | uint32_t length; |
| 99 | }; |
| 100 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 101 | struct msm_ipc_sock { |
| 102 | struct sock sk; |
| 103 | struct msm_ipc_port *port; |
Karthikeyan Ramasubramanian | 6b963bd | 2012-05-01 11:27:54 -0600 | [diff] [blame] | 104 | void *default_pil; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 107 | struct msm_ipc_router_xprt { |
| 108 | char *name; |
| 109 | uint32_t link_id; |
| 110 | void *priv; |
| 111 | |
Karthikeyan Ramasubramanian | 8cec592 | 2012-02-16 17:41:58 -0700 | [diff] [blame] | 112 | 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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 121 | void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt, |
| 122 | unsigned event, |
| 123 | void *data); |
| 124 | |
| 125 | |
| 126 | struct rr_packet *clone_pkt(struct rr_packet *pkt); |
| 127 | void release_pkt(struct rr_packet *pkt); |
| 128 | |
| 129 | |
| 130 | struct msm_ipc_port *msm_ipc_router_create_raw_port(void *endpoint, |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 131 | void (*notify)(unsigned event, void *priv), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 132 | void *priv); |
| 133 | int msm_ipc_router_send_to(struct msm_ipc_port *src, |
| 134 | struct sk_buff_head *data, |
| 135 | struct msm_ipc_addr *dest); |
| 136 | int msm_ipc_router_read(struct msm_ipc_port *port_ptr, |
| 137 | struct sk_buff_head **data, |
| 138 | size_t buf_len); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 139 | int msm_ipc_router_bind_control_port(struct msm_ipc_port *port_ptr); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 140 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 141 | int 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 Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 144 | long timeout); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 145 | int msm_ipc_router_register_server(struct msm_ipc_port *server_port, |
| 146 | struct msm_ipc_addr *name); |
| 147 | int msm_ipc_router_unregister_server(struct msm_ipc_port *server_port); |
| 148 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 149 | int msm_ipc_router_init_sockets(void); |
| 150 | void msm_ipc_router_exit_sockets(void); |
| 151 | |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 152 | void msm_ipc_sync_sec_rule(uint32_t service, uint32_t instance, void *rule); |
| 153 | |
| 154 | void msm_ipc_sync_default_sec_rule(void *rule); |
| 155 | |
Karthikeyan Ramasubramanian | 6b963bd | 2012-05-01 11:27:54 -0600 | [diff] [blame] | 156 | #if defined CONFIG_MSM_IPC_ROUTER_SMD_XPRT |
| 157 | extern void *msm_ipc_load_default_node(void); |
| 158 | |
| 159 | extern void msm_ipc_unload_default_node(void *pil); |
| 160 | #else |
| 161 | static inline void *msm_ipc_load_default_node(void) |
| 162 | { return NULL; } |
| 163 | |
| 164 | static inline void msm_ipc_unload_default_node(void *pil) { } |
| 165 | #endif |
| 166 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 167 | #endif |