Karthikeyan Ramasubramanian | 8cec592 | 2012-02-16 17:41:58 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. 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 |
| 51 | #define DEFAULT_RCV_TIMEO IPC_ROUTER_INFINITY |
| 52 | |
| 53 | #define ALIGN_SIZE(x) ((4 - ((x) & 3)) & 3) |
| 54 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 55 | union 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 | |
| 71 | struct 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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 84 | |
| 85 | struct rr_packet { |
| 86 | struct list_head list; |
| 87 | struct sk_buff_head *pkt_fragment_q; |
| 88 | uint32_t length; |
| 89 | }; |
| 90 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 91 | struct msm_ipc_sock { |
| 92 | struct sock sk; |
| 93 | struct msm_ipc_port *port; |
Karthikeyan Ramasubramanian | 6b963bd | 2012-05-01 11:27:54 -0600 | [diff] [blame] | 94 | void *default_pil; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 97 | struct msm_ipc_router_xprt { |
| 98 | char *name; |
| 99 | uint32_t link_id; |
| 100 | void *priv; |
| 101 | |
Karthikeyan Ramasubramanian | 8cec592 | 2012-02-16 17:41:58 -0700 | [diff] [blame] | 102 | 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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 111 | void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt, |
| 112 | unsigned event, |
| 113 | void *data); |
| 114 | |
| 115 | |
| 116 | struct rr_packet *clone_pkt(struct rr_packet *pkt); |
| 117 | void release_pkt(struct rr_packet *pkt); |
| 118 | |
| 119 | |
| 120 | struct msm_ipc_port *msm_ipc_router_create_raw_port(void *endpoint, |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 121 | void (*notify)(unsigned event, void *priv), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 122 | void *priv); |
| 123 | int msm_ipc_router_send_to(struct msm_ipc_port *src, |
| 124 | struct sk_buff_head *data, |
| 125 | struct msm_ipc_addr *dest); |
| 126 | int msm_ipc_router_read(struct msm_ipc_port *port_ptr, |
| 127 | struct sk_buff_head **data, |
| 128 | size_t buf_len); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 129 | 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] | 130 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 131 | int 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 Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 134 | long timeout); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 135 | int msm_ipc_router_register_server(struct msm_ipc_port *server_port, |
| 136 | struct msm_ipc_addr *name); |
| 137 | int msm_ipc_router_unregister_server(struct msm_ipc_port *server_port); |
| 138 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 139 | int msm_ipc_router_init_sockets(void); |
| 140 | void msm_ipc_router_exit_sockets(void); |
| 141 | |
Karthikeyan Ramasubramanian | 6b963bd | 2012-05-01 11:27:54 -0600 | [diff] [blame] | 142 | #if defined CONFIG_MSM_IPC_ROUTER_SMD_XPRT |
| 143 | extern void *msm_ipc_load_default_node(void); |
| 144 | |
| 145 | extern void msm_ipc_unload_default_node(void *pil); |
| 146 | #else |
| 147 | static inline void *msm_ipc_load_default_node(void) |
| 148 | { return NULL; } |
| 149 | |
| 150 | static inline void msm_ipc_unload_default_node(void *pil) { } |
| 151 | #endif |
| 152 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 153 | #endif |