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 */ |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 27 | #define IPC_ROUTER_V1 1 |
| 28 | /* |
| 29 | * Ambiguous definition but will enable multiplexing IPC_ROUTER_V2 packets |
| 30 | * with an existing alternate transport in user-space, if needed. |
| 31 | */ |
| 32 | #define IPC_ROUTER_V2 3 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 33 | |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 34 | #define IPC_ROUTER_ADDRESS 0x0000FFFF |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 35 | |
| 36 | #define IPC_ROUTER_NID_LOCAL 1 |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 37 | #define MAX_IPC_PKT_SIZE 66000 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 38 | |
| 39 | #define IPC_ROUTER_CTRL_CMD_DATA 1 |
| 40 | #define IPC_ROUTER_CTRL_CMD_HELLO 2 |
| 41 | #define IPC_ROUTER_CTRL_CMD_BYE 3 |
| 42 | #define IPC_ROUTER_CTRL_CMD_NEW_SERVER 4 |
| 43 | #define IPC_ROUTER_CTRL_CMD_REMOVE_SERVER 5 |
| 44 | #define IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT 6 |
| 45 | #define IPC_ROUTER_CTRL_CMD_RESUME_TX 7 |
| 46 | #define IPC_ROUTER_CTRL_CMD_EXIT 8 |
| 47 | #define IPC_ROUTER_CTRL_CMD_PING 9 |
| 48 | |
| 49 | #define IPC_ROUTER_DEFAULT_RX_QUOTA 5 |
| 50 | |
| 51 | #define IPC_ROUTER_XPRT_EVENT_DATA 1 |
| 52 | #define IPC_ROUTER_XPRT_EVENT_OPEN 2 |
| 53 | #define IPC_ROUTER_XPRT_EVENT_CLOSE 3 |
| 54 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 55 | #define IPC_ROUTER_INFINITY -1 |
Karthikeyan Ramasubramanian | b702923 | 2013-03-18 11:52:46 -0600 | [diff] [blame] | 56 | #define DEFAULT_RCV_TIMEO 0 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 57 | |
| 58 | #define ALIGN_SIZE(x) ((4 - ((x) & 3)) & 3) |
| 59 | |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 60 | #define ALL_SERVICE 0xFFFFFFFF |
| 61 | #define ALL_INSTANCE 0xFFFFFFFF |
| 62 | |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 63 | #define CONTROL_FLAG_CONFIRM_RX 0x1 |
| 64 | #define CONTROL_FLAG_OPT_HDR 0x2 |
| 65 | |
| 66 | #define FRAG_PKT_WRITE_ENABLE 0x1 |
| 67 | |
Karthikeyan Ramasubramanian | f7a4b6e | 2013-01-16 09:00:28 -0700 | [diff] [blame] | 68 | enum { |
| 69 | CLIENT_PORT, |
| 70 | SERVER_PORT, |
| 71 | CONTROL_PORT, |
| 72 | IRSC_PORT, |
| 73 | }; |
| 74 | |
Karthikeyan Ramasubramanian | 96cced7 | 2013-05-02 17:25:54 -0600 | [diff] [blame] | 75 | enum { |
| 76 | NULL_MODE, |
| 77 | SINGLE_LINK_MODE, |
| 78 | MULTI_LINK_MODE, |
| 79 | }; |
| 80 | |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 81 | /** |
| 82 | * rr_control_msg - Control message structure |
| 83 | * @cmd: Command identifier for HELLO message in Version 1. |
| 84 | * @hello: Message structure for HELLO message in Version 2. |
| 85 | * @srv: Message structure for NEW_SERVER/REMOVE_SERVER events. |
| 86 | * @cli: Message structure for REMOVE_CLIENT event. |
| 87 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 88 | union rr_control_msg { |
| 89 | uint32_t cmd; |
| 90 | struct { |
| 91 | uint32_t cmd; |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 92 | uint32_t magic; |
| 93 | uint32_t capability; |
| 94 | } hello; |
| 95 | struct { |
| 96 | uint32_t cmd; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 97 | uint32_t service; |
| 98 | uint32_t instance; |
| 99 | uint32_t node_id; |
| 100 | uint32_t port_id; |
| 101 | } srv; |
| 102 | struct { |
| 103 | uint32_t cmd; |
| 104 | uint32_t node_id; |
| 105 | uint32_t port_id; |
| 106 | } cli; |
| 107 | }; |
| 108 | |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 109 | /** |
| 110 | * rr_header_v1 - IPC Router header version 1 |
| 111 | * @version: Version information. |
| 112 | * @type: IPC Router Message Type. |
| 113 | * @src_node_id: Source Node ID of the message. |
| 114 | * @src_port_id: Source Port ID of the message. |
| 115 | * @control_flag: Flag to indicate flow control. |
| 116 | * @size: Size of the IPC Router payload. |
| 117 | * @dst_node_id: Destination Node ID of the message. |
| 118 | * @dst_port_id: Destination Port ID of the message. |
| 119 | */ |
| 120 | struct rr_header_v1 { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 121 | uint32_t version; |
| 122 | uint32_t type; |
| 123 | uint32_t src_node_id; |
| 124 | uint32_t src_port_id; |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 125 | uint32_t control_flag; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 126 | uint32_t size; |
| 127 | uint32_t dst_node_id; |
| 128 | uint32_t dst_port_id; |
| 129 | }; |
| 130 | |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 131 | /** |
| 132 | * rr_header_v2 - IPC Router header version 2 |
| 133 | * @version: Version information. |
| 134 | * @type: IPC Router Message Type. |
| 135 | * @control_flag: Flags to indicate flow control, optional header etc. |
| 136 | * @size: Size of the IPC Router payload. |
| 137 | * @src_node_id: Source Node ID of the message. |
| 138 | * @src_port_id: Source Port ID of the message. |
| 139 | * @dst_node_id: Destination Node ID of the message. |
| 140 | * @dst_port_id: Destination Port ID of the message. |
| 141 | */ |
| 142 | struct rr_header_v2 { |
| 143 | uint8_t version; |
| 144 | uint8_t type; |
| 145 | uint16_t control_flag; |
| 146 | uint32_t size; |
| 147 | uint16_t src_node_id; |
| 148 | uint16_t src_port_id; |
| 149 | uint16_t dst_node_id; |
| 150 | uint16_t dst_port_id; |
| 151 | } __attribute__((__packed__)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 152 | |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 153 | union rr_header { |
| 154 | struct rr_header_v1 hdr_v1; |
| 155 | struct rr_header_v2 hdr_v2; |
| 156 | }; |
| 157 | |
| 158 | #define IPC_ROUTER_HDR_SIZE sizeof(union rr_header) |
| 159 | |
| 160 | /** |
| 161 | * rr_packet - Router to Router packet structure |
| 162 | * @list: Pointer to prev & next packets in a port's rx list. |
| 163 | * @hdr: Header information extracted from or prepended to a packet. |
| 164 | * @pkt_fragment_q: Queue of SKBs containing payload. |
| 165 | * @length: Length of data in the chain of SKBs |
| 166 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 167 | struct rr_packet { |
| 168 | struct list_head list; |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 169 | struct rr_header_v1 hdr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 170 | struct sk_buff_head *pkt_fragment_q; |
| 171 | uint32_t length; |
| 172 | }; |
| 173 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 174 | struct msm_ipc_sock { |
| 175 | struct sock sk; |
| 176 | struct msm_ipc_port *port; |
Karthikeyan Ramasubramanian | 88f02e5 | 2013-06-03 12:05:50 -0600 | [diff] [blame] | 177 | void *default_pil; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 178 | }; |
| 179 | |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 180 | /** |
| 181 | * msm_ipc_router_xprt - Structure to hold XPRT specific information |
| 182 | * @name: Name of the XPRT. |
| 183 | * @link_id: Network cluster ID to which the XPRT belongs to. |
| 184 | * @priv: XPRT's private data. |
| 185 | * @get_version: Method to get header version supported by the XPRT. |
| 186 | * @get_option: Method to get XPRT specific options. |
| 187 | * @read_avail: Method to get data size available to be read from the XPRT. |
| 188 | * @read: Method to read data from the XPRT. |
| 189 | * @write_avail: Method to get write space available in the XPRT. |
| 190 | * @write: Method to write data to the XPRT. |
| 191 | * @close: Method to close the XPRT. |
| 192 | * @sft_close_done: Method to indicate to the XPRT that handling of reset |
| 193 | * event is complete. |
| 194 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 195 | struct msm_ipc_router_xprt { |
| 196 | char *name; |
| 197 | uint32_t link_id; |
| 198 | void *priv; |
| 199 | |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 200 | int (*get_version)(struct msm_ipc_router_xprt *xprt); |
| 201 | int (*get_option)(struct msm_ipc_router_xprt *xprt); |
Karthikeyan Ramasubramanian | 8cec592 | 2012-02-16 17:41:58 -0700 | [diff] [blame] | 202 | int (*read_avail)(struct msm_ipc_router_xprt *xprt); |
| 203 | int (*read)(void *data, uint32_t len, |
| 204 | struct msm_ipc_router_xprt *xprt); |
| 205 | int (*write_avail)(struct msm_ipc_router_xprt *xprt); |
| 206 | int (*write)(void *data, uint32_t len, |
| 207 | struct msm_ipc_router_xprt *xprt); |
| 208 | int (*close)(struct msm_ipc_router_xprt *xprt); |
Karthikeyan Ramasubramanian | e6ef0a2 | 2013-06-12 11:49:26 -0600 | [diff] [blame] | 209 | void (*sft_close_done)(struct msm_ipc_router_xprt *xprt); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 210 | }; |
| 211 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 212 | void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt, |
| 213 | unsigned event, |
| 214 | void *data); |
| 215 | |
| 216 | |
| 217 | struct rr_packet *clone_pkt(struct rr_packet *pkt); |
| 218 | void release_pkt(struct rr_packet *pkt); |
| 219 | |
| 220 | |
| 221 | struct msm_ipc_port *msm_ipc_router_create_raw_port(void *endpoint, |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 222 | void (*notify)(unsigned event, void *priv), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 223 | void *priv); |
| 224 | int msm_ipc_router_send_to(struct msm_ipc_port *src, |
| 225 | struct sk_buff_head *data, |
| 226 | struct msm_ipc_addr *dest); |
| 227 | int msm_ipc_router_read(struct msm_ipc_port *port_ptr, |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 228 | struct rr_packet **pkt, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 229 | size_t buf_len); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 230 | 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] | 231 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 232 | int msm_ipc_router_recv_from(struct msm_ipc_port *port_ptr, |
Karthikeyan Ramasubramanian | 7edb680 | 2013-04-16 23:12:44 -0600 | [diff] [blame] | 233 | struct rr_packet **pkt, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 234 | struct msm_ipc_addr *src_addr, |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 235 | long timeout); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 236 | int msm_ipc_router_register_server(struct msm_ipc_port *server_port, |
| 237 | struct msm_ipc_addr *name); |
| 238 | int msm_ipc_router_unregister_server(struct msm_ipc_port *server_port); |
| 239 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 240 | int msm_ipc_router_init_sockets(void); |
| 241 | void msm_ipc_router_exit_sockets(void); |
| 242 | |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 243 | void msm_ipc_sync_sec_rule(uint32_t service, uint32_t instance, void *rule); |
| 244 | |
| 245 | void msm_ipc_sync_default_sec_rule(void *rule); |
| 246 | |
Arun Kumar Neelakantam | 0af9676 | 2013-06-21 17:57:18 +0530 | [diff] [blame] | 247 | int msm_ipc_router_rx_data_wait(struct msm_ipc_port *port_ptr, long timeout); |
| 248 | |
Karthikeyan Ramasubramanian | 88f02e5 | 2013-06-03 12:05:50 -0600 | [diff] [blame] | 249 | #if defined CONFIG_MSM_IPC_ROUTER_SMD_XPRT |
| 250 | extern void *msm_ipc_load_default_node(void); |
| 251 | |
| 252 | extern void msm_ipc_unload_default_node(void *pil); |
| 253 | #else |
| 254 | static inline void *msm_ipc_load_default_node(void) |
| 255 | { return NULL; } |
| 256 | |
| 257 | static inline void msm_ipc_unload_default_node(void *pil) { } |
| 258 | #endif |
| 259 | |
Zaheerulla Meer | 7442525 | 2013-08-20 12:02:31 +0530 | [diff] [blame] | 260 | void msm_ipc_router_free_skb(struct sk_buff_head *skb_head); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 261 | #endif |