Karthikeyan Ramasubramanian | 5c568fb | 2013-01-10 17:09:13 -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 | #define DEBUG |
| 14 | |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/string.h> |
| 19 | #include <linux/errno.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/err.h> |
| 24 | #include <linux/sched.h> |
| 25 | #include <linux/poll.h> |
| 26 | #include <linux/wakelock.h> |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/uaccess.h> |
| 29 | #include <linux/debugfs.h> |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 30 | #include <linux/rwsem.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 31 | |
| 32 | #include <asm/uaccess.h> |
| 33 | #include <asm/byteorder.h> |
| 34 | |
| 35 | #include <mach/smem_log.h> |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 36 | #include <mach/subsystem_notif.h> |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 37 | #include <mach/msm_ipc_router.h> |
Karthikeyan Ramasubramanian | 2bfe8ec | 2013-03-22 10:47:20 -0600 | [diff] [blame] | 38 | #include <mach/msm_ipc_logging.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 39 | |
| 40 | #include "ipc_router.h" |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 41 | #include "modem_notifier.h" |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 42 | #include "msm_ipc_router_security.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 43 | |
| 44 | enum { |
| 45 | SMEM_LOG = 1U << 0, |
| 46 | RTR_DBG = 1U << 1, |
| 47 | R2R_MSG = 1U << 2, |
| 48 | R2R_RAW = 1U << 3, |
| 49 | NTFY_MSG = 1U << 4, |
| 50 | R2R_RAW_HDR = 1U << 5, |
| 51 | }; |
| 52 | |
| 53 | static int msm_ipc_router_debug_mask; |
| 54 | module_param_named(debug_mask, msm_ipc_router_debug_mask, |
| 55 | int, S_IRUGO | S_IWUSR | S_IWGRP); |
| 56 | |
Karthikeyan Ramasubramanian | 2bfe8ec | 2013-03-22 10:47:20 -0600 | [diff] [blame] | 57 | static void *ipc_rtr_log_ctxt; |
| 58 | #define IPC_RTR_LOG_PAGES 5 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 59 | #define DIAG(x...) pr_info("[RR] ERROR " x) |
| 60 | |
| 61 | #if defined(DEBUG) |
| 62 | #define D(x...) do { \ |
Karthikeyan Ramasubramanian | 2bfe8ec | 2013-03-22 10:47:20 -0600 | [diff] [blame] | 63 | if (ipc_rtr_log_ctxt) \ |
| 64 | ipc_log_string(ipc_rtr_log_ctxt, x); \ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 65 | if (msm_ipc_router_debug_mask & RTR_DBG) \ |
| 66 | pr_info(x); \ |
| 67 | } while (0) |
| 68 | |
| 69 | #define RR(x...) do { \ |
Karthikeyan Ramasubramanian | 2bfe8ec | 2013-03-22 10:47:20 -0600 | [diff] [blame] | 70 | if (ipc_rtr_log_ctxt) \ |
| 71 | ipc_log_string(ipc_rtr_log_ctxt, x); \ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 72 | if (msm_ipc_router_debug_mask & R2R_MSG) \ |
| 73 | pr_info("[RR] "x); \ |
| 74 | } while (0) |
| 75 | |
| 76 | #define RAW(x...) do { \ |
| 77 | if (msm_ipc_router_debug_mask & R2R_RAW) \ |
| 78 | pr_info("[RAW] "x); \ |
| 79 | } while (0) |
| 80 | |
| 81 | #define NTFY(x...) do { \ |
| 82 | if (msm_ipc_router_debug_mask & NTFY_MSG) \ |
| 83 | pr_info("[NOTIFY] "x); \ |
| 84 | } while (0) |
| 85 | |
| 86 | #define RAW_HDR(x...) do { \ |
| 87 | if (msm_ipc_router_debug_mask & R2R_RAW_HDR) \ |
| 88 | pr_info("[HDR] "x); \ |
| 89 | } while (0) |
| 90 | #else |
| 91 | #define D(x...) do { } while (0) |
| 92 | #define RR(x...) do { } while (0) |
| 93 | #define RAW(x...) do { } while (0) |
| 94 | #define RAW_HDR(x...) do { } while (0) |
| 95 | #define NTFY(x...) do { } while (0) |
| 96 | #endif |
| 97 | |
| 98 | #define IPC_ROUTER_LOG_EVENT_ERROR 0x10 |
| 99 | #define IPC_ROUTER_LOG_EVENT_TX 0x11 |
| 100 | #define IPC_ROUTER_LOG_EVENT_RX 0x12 |
| 101 | |
| 102 | static LIST_HEAD(control_ports); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 103 | static DECLARE_RWSEM(control_ports_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 104 | |
| 105 | #define LP_HASH_SIZE 32 |
| 106 | static struct list_head local_ports[LP_HASH_SIZE]; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 107 | static DECLARE_RWSEM(local_ports_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 108 | |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 109 | /* |
| 110 | * Server info is organized as a hash table. The server's service ID is |
| 111 | * used to index into the hash table. The instance ID of most of the servers |
| 112 | * are 1 or 2. The service IDs are well distributed compared to the instance |
| 113 | * IDs and hence choosing service ID to index into this hash table optimizes |
| 114 | * the hash table operations like add, lookup, destroy. |
| 115 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 116 | #define SRV_HASH_SIZE 32 |
| 117 | static struct list_head server_list[SRV_HASH_SIZE]; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 118 | static DECLARE_RWSEM(server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 119 | |
| 120 | struct msm_ipc_server { |
| 121 | struct list_head list; |
| 122 | struct msm_ipc_port_name name; |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 123 | char pdev_name[32]; |
| 124 | int next_pdev_id; |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 125 | int synced_sec_rule; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 126 | struct list_head server_port_list; |
| 127 | }; |
| 128 | |
| 129 | struct msm_ipc_server_port { |
| 130 | struct list_head list; |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 131 | struct platform_device pdev; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 132 | struct msm_ipc_port_addr server_addr; |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 133 | struct msm_ipc_router_xprt_info *xprt_info; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 136 | struct msm_ipc_resume_tx_port { |
| 137 | struct list_head list; |
| 138 | uint32_t port_id; |
| 139 | uint32_t node_id; |
| 140 | }; |
| 141 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 142 | #define RP_HASH_SIZE 32 |
| 143 | struct msm_ipc_router_remote_port { |
| 144 | struct list_head list; |
| 145 | uint32_t node_id; |
| 146 | uint32_t port_id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 147 | uint32_t tx_quota_cnt; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 148 | struct mutex quota_lock_lhb2; |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 149 | struct list_head resume_tx_port_list; |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 150 | void *sec_rule; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 151 | struct msm_ipc_server *server; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | struct msm_ipc_router_xprt_info { |
| 155 | struct list_head list; |
| 156 | struct msm_ipc_router_xprt *xprt; |
| 157 | uint32_t remote_node_id; |
| 158 | uint32_t initialized; |
| 159 | struct list_head pkt_list; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 160 | struct wake_lock wakelock; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 161 | struct mutex rx_lock_lhb2; |
| 162 | struct mutex tx_lock_lhb2; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 163 | uint32_t need_len; |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 164 | uint32_t abort_data_read; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 165 | struct work_struct read_data; |
| 166 | struct workqueue_struct *workqueue; |
| 167 | }; |
| 168 | |
| 169 | #define RT_HASH_SIZE 4 |
| 170 | struct msm_ipc_routing_table_entry { |
| 171 | struct list_head list; |
| 172 | uint32_t node_id; |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 173 | uint32_t neighbor_node_id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 174 | struct list_head remote_port_list[RP_HASH_SIZE]; |
| 175 | struct msm_ipc_router_xprt_info *xprt_info; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 176 | struct rw_semaphore lock_lha4; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 177 | unsigned long num_tx_bytes; |
| 178 | unsigned long num_rx_bytes; |
| 179 | }; |
| 180 | |
| 181 | static struct list_head routing_table[RT_HASH_SIZE]; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 182 | static DECLARE_RWSEM(routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 183 | static int routing_table_inited; |
| 184 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 185 | static void do_read_data(struct work_struct *work); |
| 186 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 187 | static LIST_HEAD(xprt_info_list); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 188 | static DECLARE_RWSEM(xprt_info_list_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 189 | |
Karthikeyan Ramasubramanian | 4af9f7c | 2011-09-30 15:55:18 -0600 | [diff] [blame] | 190 | static DECLARE_COMPLETION(msm_ipc_local_router_up); |
| 191 | #define IPC_ROUTER_INIT_TIMEOUT (10 * HZ) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 192 | |
| 193 | static uint32_t next_port_id; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 194 | static DEFINE_MUTEX(next_port_id_lock_lha1); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 195 | static struct workqueue_struct *msm_ipc_router_workqueue; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 196 | |
| 197 | enum { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 198 | DOWN, |
| 199 | UP, |
| 200 | }; |
| 201 | |
| 202 | static void init_routing_table(void) |
| 203 | { |
| 204 | int i; |
| 205 | for (i = 0; i < RT_HASH_SIZE; i++) |
| 206 | INIT_LIST_HEAD(&routing_table[i]); |
| 207 | } |
| 208 | |
| 209 | static struct msm_ipc_routing_table_entry *alloc_routing_table_entry( |
| 210 | uint32_t node_id) |
| 211 | { |
| 212 | int i; |
| 213 | struct msm_ipc_routing_table_entry *rt_entry; |
| 214 | |
| 215 | rt_entry = kmalloc(sizeof(struct msm_ipc_routing_table_entry), |
| 216 | GFP_KERNEL); |
| 217 | if (!rt_entry) { |
| 218 | pr_err("%s: rt_entry allocation failed for %d\n", |
| 219 | __func__, node_id); |
| 220 | return NULL; |
| 221 | } |
| 222 | |
| 223 | for (i = 0; i < RP_HASH_SIZE; i++) |
| 224 | INIT_LIST_HEAD(&rt_entry->remote_port_list[i]); |
| 225 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 226 | init_rwsem(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 227 | rt_entry->node_id = node_id; |
| 228 | rt_entry->xprt_info = NULL; |
| 229 | return rt_entry; |
| 230 | } |
| 231 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 232 | /* Must be called with routing_table_lock_lha3 locked. */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 233 | static int add_routing_table_entry( |
| 234 | struct msm_ipc_routing_table_entry *rt_entry) |
| 235 | { |
| 236 | uint32_t key; |
| 237 | |
| 238 | if (!rt_entry) |
| 239 | return -EINVAL; |
| 240 | |
| 241 | key = (rt_entry->node_id % RT_HASH_SIZE); |
| 242 | list_add_tail(&rt_entry->list, &routing_table[key]); |
| 243 | return 0; |
| 244 | } |
| 245 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 246 | /* Must be called with routing_table_lock_lha3 locked. */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 247 | static struct msm_ipc_routing_table_entry *lookup_routing_table( |
| 248 | uint32_t node_id) |
| 249 | { |
| 250 | uint32_t key = (node_id % RT_HASH_SIZE); |
| 251 | struct msm_ipc_routing_table_entry *rt_entry; |
| 252 | |
| 253 | list_for_each_entry(rt_entry, &routing_table[key], list) { |
| 254 | if (rt_entry->node_id == node_id) |
| 255 | return rt_entry; |
| 256 | } |
| 257 | return NULL; |
| 258 | } |
| 259 | |
| 260 | struct rr_packet *rr_read(struct msm_ipc_router_xprt_info *xprt_info) |
| 261 | { |
| 262 | struct rr_packet *temp_pkt; |
| 263 | |
| 264 | if (!xprt_info) |
| 265 | return NULL; |
| 266 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 267 | mutex_lock(&xprt_info->rx_lock_lhb2); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 268 | if (xprt_info->abort_data_read) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 269 | mutex_unlock(&xprt_info->rx_lock_lhb2); |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 270 | pr_err("%s detected SSR & exiting now\n", |
| 271 | xprt_info->xprt->name); |
| 272 | return NULL; |
| 273 | } |
| 274 | |
| 275 | if (list_empty(&xprt_info->pkt_list)) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 276 | mutex_unlock(&xprt_info->rx_lock_lhb2); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 277 | return NULL; |
| 278 | } |
| 279 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 280 | temp_pkt = list_first_entry(&xprt_info->pkt_list, |
| 281 | struct rr_packet, list); |
| 282 | list_del(&temp_pkt->list); |
| 283 | if (list_empty(&xprt_info->pkt_list)) |
| 284 | wake_unlock(&xprt_info->wakelock); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 285 | mutex_unlock(&xprt_info->rx_lock_lhb2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 286 | return temp_pkt; |
| 287 | } |
| 288 | |
| 289 | struct rr_packet *clone_pkt(struct rr_packet *pkt) |
| 290 | { |
| 291 | struct rr_packet *cloned_pkt; |
| 292 | struct sk_buff *temp_skb, *cloned_skb; |
| 293 | struct sk_buff_head *pkt_fragment_q; |
| 294 | |
| 295 | cloned_pkt = kzalloc(sizeof(struct rr_packet), GFP_KERNEL); |
| 296 | if (!cloned_pkt) { |
| 297 | pr_err("%s: failure\n", __func__); |
| 298 | return NULL; |
| 299 | } |
| 300 | |
| 301 | pkt_fragment_q = kmalloc(sizeof(struct sk_buff_head), GFP_KERNEL); |
| 302 | if (!pkt_fragment_q) { |
| 303 | pr_err("%s: pkt_frag_q alloc failure\n", __func__); |
| 304 | kfree(cloned_pkt); |
| 305 | return NULL; |
| 306 | } |
| 307 | skb_queue_head_init(pkt_fragment_q); |
| 308 | |
| 309 | skb_queue_walk(pkt->pkt_fragment_q, temp_skb) { |
| 310 | cloned_skb = skb_clone(temp_skb, GFP_KERNEL); |
| 311 | if (!cloned_skb) |
| 312 | goto fail_clone; |
| 313 | skb_queue_tail(pkt_fragment_q, cloned_skb); |
| 314 | } |
| 315 | cloned_pkt->pkt_fragment_q = pkt_fragment_q; |
| 316 | cloned_pkt->length = pkt->length; |
| 317 | return cloned_pkt; |
| 318 | |
| 319 | fail_clone: |
| 320 | while (!skb_queue_empty(pkt_fragment_q)) { |
| 321 | temp_skb = skb_dequeue(pkt_fragment_q); |
| 322 | kfree_skb(temp_skb); |
| 323 | } |
| 324 | kfree(pkt_fragment_q); |
| 325 | kfree(cloned_pkt); |
| 326 | return NULL; |
| 327 | } |
| 328 | |
| 329 | struct rr_packet *create_pkt(struct sk_buff_head *data) |
| 330 | { |
| 331 | struct rr_packet *pkt; |
| 332 | struct sk_buff *temp_skb; |
| 333 | |
| 334 | pkt = kzalloc(sizeof(struct rr_packet), GFP_KERNEL); |
| 335 | if (!pkt) { |
| 336 | pr_err("%s: failure\n", __func__); |
| 337 | return NULL; |
| 338 | } |
| 339 | |
| 340 | pkt->pkt_fragment_q = data; |
| 341 | skb_queue_walk(pkt->pkt_fragment_q, temp_skb) |
| 342 | pkt->length += temp_skb->len; |
| 343 | return pkt; |
| 344 | } |
| 345 | |
| 346 | void release_pkt(struct rr_packet *pkt) |
| 347 | { |
| 348 | struct sk_buff *temp_skb; |
| 349 | |
| 350 | if (!pkt) |
| 351 | return; |
| 352 | |
| 353 | if (!pkt->pkt_fragment_q) { |
| 354 | kfree(pkt); |
| 355 | return; |
| 356 | } |
| 357 | |
| 358 | while (!skb_queue_empty(pkt->pkt_fragment_q)) { |
| 359 | temp_skb = skb_dequeue(pkt->pkt_fragment_q); |
| 360 | kfree_skb(temp_skb); |
| 361 | } |
| 362 | kfree(pkt->pkt_fragment_q); |
| 363 | kfree(pkt); |
| 364 | return; |
| 365 | } |
| 366 | |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 367 | static struct sk_buff_head *msm_ipc_router_buf_to_skb(void *buf, |
| 368 | unsigned int buf_len) |
| 369 | { |
| 370 | struct sk_buff_head *skb_head; |
| 371 | struct sk_buff *skb; |
| 372 | int first = 1, offset = 0; |
| 373 | int skb_size, data_size; |
| 374 | void *data; |
| 375 | |
| 376 | skb_head = kmalloc(sizeof(struct sk_buff_head), GFP_KERNEL); |
| 377 | if (!skb_head) { |
| 378 | pr_err("%s: Couldnot allocate skb_head\n", __func__); |
| 379 | return NULL; |
| 380 | } |
| 381 | skb_queue_head_init(skb_head); |
| 382 | |
| 383 | data_size = buf_len; |
| 384 | while (offset != buf_len) { |
| 385 | skb_size = data_size; |
| 386 | if (first) |
| 387 | skb_size += IPC_ROUTER_HDR_SIZE; |
| 388 | |
| 389 | skb = alloc_skb(skb_size, GFP_KERNEL); |
| 390 | if (!skb) { |
| 391 | if (skb_size <= (PAGE_SIZE/2)) { |
| 392 | pr_err("%s: cannot allocate skb\n", __func__); |
| 393 | goto buf_to_skb_error; |
| 394 | } |
| 395 | data_size = data_size / 2; |
| 396 | continue; |
| 397 | } |
| 398 | |
| 399 | if (first) { |
| 400 | skb_reserve(skb, IPC_ROUTER_HDR_SIZE); |
| 401 | first = 0; |
| 402 | } |
| 403 | |
| 404 | data = skb_put(skb, data_size); |
| 405 | memcpy(skb->data, buf + offset, data_size); |
| 406 | skb_queue_tail(skb_head, skb); |
| 407 | offset += data_size; |
| 408 | data_size = buf_len - offset; |
| 409 | } |
| 410 | return skb_head; |
| 411 | |
| 412 | buf_to_skb_error: |
| 413 | while (!skb_queue_empty(skb_head)) { |
| 414 | skb = skb_dequeue(skb_head); |
| 415 | kfree_skb(skb); |
| 416 | } |
| 417 | kfree(skb_head); |
| 418 | return NULL; |
| 419 | } |
| 420 | |
| 421 | static void *msm_ipc_router_skb_to_buf(struct sk_buff_head *skb_head, |
| 422 | unsigned int len) |
| 423 | { |
| 424 | struct sk_buff *temp; |
| 425 | int offset = 0, buf_len = 0, copy_len; |
| 426 | void *buf; |
| 427 | |
| 428 | if (!skb_head) { |
| 429 | pr_err("%s: NULL skb_head\n", __func__); |
| 430 | return NULL; |
| 431 | } |
| 432 | |
| 433 | temp = skb_peek(skb_head); |
| 434 | buf_len = len; |
| 435 | buf = kmalloc(buf_len, GFP_KERNEL); |
| 436 | if (!buf) { |
| 437 | pr_err("%s: cannot allocate buf\n", __func__); |
| 438 | return NULL; |
| 439 | } |
| 440 | skb_queue_walk(skb_head, temp) { |
| 441 | copy_len = buf_len < temp->len ? buf_len : temp->len; |
| 442 | memcpy(buf + offset, temp->data, copy_len); |
| 443 | offset += copy_len; |
| 444 | buf_len -= copy_len; |
| 445 | } |
| 446 | return buf; |
| 447 | } |
| 448 | |
| 449 | static void msm_ipc_router_free_skb(struct sk_buff_head *skb_head) |
| 450 | { |
| 451 | struct sk_buff *temp_skb; |
| 452 | |
| 453 | if (!skb_head) |
| 454 | return; |
| 455 | |
| 456 | while (!skb_queue_empty(skb_head)) { |
| 457 | temp_skb = skb_dequeue(skb_head); |
| 458 | kfree_skb(temp_skb); |
| 459 | } |
| 460 | kfree(skb_head); |
| 461 | } |
| 462 | |
Karthikeyan Ramasubramanian | 6dbb00f | 2013-05-17 15:19:56 -0600 | [diff] [blame] | 463 | static int post_pkt_to_port(struct msm_ipc_port *port_ptr, |
| 464 | struct rr_packet *pkt, int clone) |
| 465 | { |
| 466 | struct rr_packet *temp_pkt = pkt; |
Zaheerulla Meer | 84d0bd56 | 2013-05-24 21:19:18 +0530 | [diff] [blame] | 467 | void (*notify)(unsigned event, void *priv); |
Karthikeyan Ramasubramanian | 6dbb00f | 2013-05-17 15:19:56 -0600 | [diff] [blame] | 468 | |
| 469 | if (unlikely(!port_ptr || !pkt)) |
| 470 | return -EINVAL; |
| 471 | |
| 472 | if (clone) { |
| 473 | temp_pkt = clone_pkt(pkt); |
| 474 | if (!temp_pkt) { |
| 475 | pr_err("%s: Error cloning packet for port %08x:%08x\n", |
| 476 | __func__, port_ptr->this_port.node_id, |
| 477 | port_ptr->this_port.port_id); |
| 478 | return -ENOMEM; |
| 479 | } |
| 480 | } |
| 481 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 482 | mutex_lock(&port_ptr->port_rx_q_lock_lhb3); |
Karthikeyan Ramasubramanian | 6dbb00f | 2013-05-17 15:19:56 -0600 | [diff] [blame] | 483 | wake_lock(&port_ptr->port_rx_wake_lock); |
| 484 | list_add_tail(&temp_pkt->list, &port_ptr->port_rx_q); |
| 485 | wake_up(&port_ptr->port_rx_wait_q); |
Zaheerulla Meer | 84d0bd56 | 2013-05-24 21:19:18 +0530 | [diff] [blame] | 486 | notify = port_ptr->notify; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 487 | mutex_unlock(&port_ptr->port_rx_q_lock_lhb3); |
Zaheerulla Meer | 84d0bd56 | 2013-05-24 21:19:18 +0530 | [diff] [blame] | 488 | if (notify) |
| 489 | notify(MSM_IPC_ROUTER_READ_CB, port_ptr->priv); |
Karthikeyan Ramasubramanian | 6dbb00f | 2013-05-17 15:19:56 -0600 | [diff] [blame] | 490 | return 0; |
| 491 | } |
| 492 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 493 | static int post_control_ports(struct rr_packet *pkt) |
| 494 | { |
| 495 | struct msm_ipc_port *port_ptr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 496 | |
| 497 | if (!pkt) |
| 498 | return -EINVAL; |
| 499 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 500 | down_read(&control_ports_lock_lha5); |
Karthikeyan Ramasubramanian | 6dbb00f | 2013-05-17 15:19:56 -0600 | [diff] [blame] | 501 | list_for_each_entry(port_ptr, &control_ports, list) |
| 502 | post_pkt_to_port(port_ptr, pkt, 1); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 503 | up_read(&control_ports_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | static uint32_t allocate_port_id(void) |
| 508 | { |
| 509 | uint32_t port_id = 0, prev_port_id, key; |
| 510 | struct msm_ipc_port *port_ptr; |
| 511 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 512 | mutex_lock(&next_port_id_lock_lha1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 513 | prev_port_id = next_port_id; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 514 | down_read(&local_ports_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 515 | do { |
| 516 | next_port_id++; |
| 517 | if ((next_port_id & 0xFFFFFFFE) == 0xFFFFFFFE) |
| 518 | next_port_id = 1; |
| 519 | |
| 520 | key = (next_port_id & (LP_HASH_SIZE - 1)); |
| 521 | if (list_empty(&local_ports[key])) { |
| 522 | port_id = next_port_id; |
| 523 | break; |
| 524 | } |
| 525 | list_for_each_entry(port_ptr, &local_ports[key], list) { |
| 526 | if (port_ptr->this_port.port_id == next_port_id) { |
| 527 | port_id = next_port_id; |
| 528 | break; |
| 529 | } |
| 530 | } |
| 531 | if (!port_id) { |
| 532 | port_id = next_port_id; |
| 533 | break; |
| 534 | } |
| 535 | port_id = 0; |
| 536 | } while (next_port_id != prev_port_id); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 537 | up_read(&local_ports_lock_lha2); |
| 538 | mutex_unlock(&next_port_id_lock_lha1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 539 | |
| 540 | return port_id; |
| 541 | } |
| 542 | |
| 543 | void msm_ipc_router_add_local_port(struct msm_ipc_port *port_ptr) |
| 544 | { |
| 545 | uint32_t key; |
| 546 | |
| 547 | if (!port_ptr) |
| 548 | return; |
| 549 | |
| 550 | key = (port_ptr->this_port.port_id & (LP_HASH_SIZE - 1)); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 551 | down_write(&local_ports_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 552 | list_add_tail(&port_ptr->list, &local_ports[key]); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 553 | up_write(&local_ports_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | struct msm_ipc_port *msm_ipc_router_create_raw_port(void *endpoint, |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 557 | void (*notify)(unsigned event, void *priv), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 558 | void *priv) |
| 559 | { |
| 560 | struct msm_ipc_port *port_ptr; |
| 561 | |
| 562 | port_ptr = kzalloc(sizeof(struct msm_ipc_port), GFP_KERNEL); |
| 563 | if (!port_ptr) |
| 564 | return NULL; |
| 565 | |
| 566 | port_ptr->this_port.node_id = IPC_ROUTER_NID_LOCAL; |
| 567 | port_ptr->this_port.port_id = allocate_port_id(); |
| 568 | if (!port_ptr->this_port.port_id) { |
| 569 | pr_err("%s: All port ids are in use\n", __func__); |
| 570 | kfree(port_ptr); |
| 571 | return NULL; |
| 572 | } |
| 573 | |
| 574 | spin_lock_init(&port_ptr->port_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 575 | INIT_LIST_HEAD(&port_ptr->port_rx_q); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 576 | mutex_init(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 577 | init_waitqueue_head(&port_ptr->port_rx_wait_q); |
Karthikeyan Ramasubramanian | b4aeeb9 | 2012-03-13 12:31:43 -0600 | [diff] [blame] | 578 | snprintf(port_ptr->rx_wakelock_name, MAX_WAKELOCK_NAME_SZ, |
Karthikeyan Ramasubramanian | 6396bdd | 2013-02-14 13:53:20 -0700 | [diff] [blame] | 579 | "ipc%08x_%s", |
| 580 | port_ptr->this_port.port_id, |
| 581 | current->comm); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 582 | wake_lock_init(&port_ptr->port_rx_wake_lock, |
Karthikeyan Ramasubramanian | b4aeeb9 | 2012-03-13 12:31:43 -0600 | [diff] [blame] | 583 | WAKE_LOCK_SUSPEND, port_ptr->rx_wakelock_name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 584 | |
| 585 | port_ptr->endpoint = endpoint; |
| 586 | port_ptr->notify = notify; |
| 587 | port_ptr->priv = priv; |
| 588 | |
| 589 | msm_ipc_router_add_local_port(port_ptr); |
| 590 | return port_ptr; |
| 591 | } |
| 592 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 593 | /* Must be called with local_ports_lock_lha2 locked. */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 594 | static struct msm_ipc_port *msm_ipc_router_lookup_local_port(uint32_t port_id) |
| 595 | { |
| 596 | int key = (port_id & (LP_HASH_SIZE - 1)); |
| 597 | struct msm_ipc_port *port_ptr; |
| 598 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 599 | list_for_each_entry(port_ptr, &local_ports[key], list) { |
| 600 | if (port_ptr->this_port.port_id == port_id) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 601 | return port_ptr; |
| 602 | } |
| 603 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 604 | return NULL; |
| 605 | } |
| 606 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 607 | /* Must be called with routing_table_lock_lha3 locked. */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 608 | static struct msm_ipc_router_remote_port *msm_ipc_router_lookup_remote_port( |
| 609 | uint32_t node_id, |
| 610 | uint32_t port_id) |
| 611 | { |
| 612 | struct msm_ipc_router_remote_port *rport_ptr; |
| 613 | struct msm_ipc_routing_table_entry *rt_entry; |
| 614 | int key = (port_id & (RP_HASH_SIZE - 1)); |
| 615 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 616 | rt_entry = lookup_routing_table(node_id); |
| 617 | if (!rt_entry) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 618 | pr_err("%s: Node is not up\n", __func__); |
| 619 | return NULL; |
| 620 | } |
| 621 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 622 | down_read(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 623 | list_for_each_entry(rport_ptr, |
| 624 | &rt_entry->remote_port_list[key], list) { |
| 625 | if (rport_ptr->port_id == port_id) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 626 | up_read(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 627 | return rport_ptr; |
| 628 | } |
| 629 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 630 | up_read(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 631 | return NULL; |
| 632 | } |
| 633 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 634 | /* Must be called with routing_table_lock_lha3 locked. */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 635 | static struct msm_ipc_router_remote_port *msm_ipc_router_create_remote_port( |
| 636 | uint32_t node_id, |
| 637 | uint32_t port_id) |
| 638 | { |
| 639 | struct msm_ipc_router_remote_port *rport_ptr; |
| 640 | struct msm_ipc_routing_table_entry *rt_entry; |
| 641 | int key = (port_id & (RP_HASH_SIZE - 1)); |
| 642 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 643 | rt_entry = lookup_routing_table(node_id); |
| 644 | if (!rt_entry) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 645 | pr_err("%s: Node is not up\n", __func__); |
| 646 | return NULL; |
| 647 | } |
| 648 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 649 | rport_ptr = kmalloc(sizeof(struct msm_ipc_router_remote_port), |
| 650 | GFP_KERNEL); |
| 651 | if (!rport_ptr) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 652 | pr_err("%s: Remote port alloc failed\n", __func__); |
| 653 | return NULL; |
| 654 | } |
| 655 | rport_ptr->port_id = port_id; |
| 656 | rport_ptr->node_id = node_id; |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 657 | rport_ptr->sec_rule = NULL; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 658 | rport_ptr->server = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 659 | rport_ptr->tx_quota_cnt = 0; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 660 | mutex_init(&rport_ptr->quota_lock_lhb2); |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 661 | INIT_LIST_HEAD(&rport_ptr->resume_tx_port_list); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 662 | down_write(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 663 | list_add_tail(&rport_ptr->list, |
| 664 | &rt_entry->remote_port_list[key]); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 665 | up_write(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 666 | return rport_ptr; |
| 667 | } |
| 668 | |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 669 | /** |
| 670 | * msm_ipc_router_free_resume_tx_port() - Free the resume_tx ports |
| 671 | * @rport_ptr: Pointer to the remote port. |
| 672 | * |
| 673 | * This function deletes all the resume_tx ports associated with a remote port |
| 674 | * and frees the memory allocated to each resume_tx port. |
| 675 | * |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 676 | * Must be called with rport_ptr->quota_lock_lhb2 locked. |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 677 | */ |
| 678 | static void msm_ipc_router_free_resume_tx_port( |
| 679 | struct msm_ipc_router_remote_port *rport_ptr) |
| 680 | { |
| 681 | struct msm_ipc_resume_tx_port *rtx_port, *tmp_rtx_port; |
| 682 | |
| 683 | list_for_each_entry_safe(rtx_port, tmp_rtx_port, |
| 684 | &rport_ptr->resume_tx_port_list, list) { |
| 685 | list_del(&rtx_port->list); |
| 686 | kfree(rtx_port); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * msm_ipc_router_lookup_resume_tx_port() - Lookup resume_tx port list |
| 692 | * @rport_ptr: Remote port whose resume_tx port list needs to be looked. |
| 693 | * @port_id: Port ID which needs to be looked from the list. |
| 694 | * |
| 695 | * return 1 if the port_id is found in the list, else 0. |
| 696 | * |
| 697 | * This function is used to lookup the existence of a local port in |
| 698 | * remote port's resume_tx list. This function is used to ensure that |
| 699 | * the same port is not added to the remote_port's resume_tx list repeatedly. |
| 700 | * |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 701 | * Must be called with rport_ptr->quota_lock_lhb2 locked. |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 702 | */ |
| 703 | static int msm_ipc_router_lookup_resume_tx_port( |
| 704 | struct msm_ipc_router_remote_port *rport_ptr, uint32_t port_id) |
| 705 | { |
| 706 | struct msm_ipc_resume_tx_port *rtx_port; |
| 707 | |
| 708 | list_for_each_entry(rtx_port, &rport_ptr->resume_tx_port_list, list) { |
| 709 | if (port_id == rtx_port->port_id) |
| 710 | return 1; |
| 711 | } |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | /** |
| 716 | * post_resume_tx() - Post the resume_tx event |
| 717 | * @rport_ptr: Pointer to the remote port |
| 718 | * @pkt : The data packet that is received on a resume_tx event |
| 719 | * |
| 720 | * This function informs about the reception of the resume_tx message from a |
| 721 | * remote port pointed by rport_ptr to all the local ports that are in the |
| 722 | * resume_tx_ports_list of this remote port. On posting the information, this |
| 723 | * function sequentially deletes each entry in the resume_tx_port_list of the |
| 724 | * remote port. |
| 725 | * |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 726 | * Must be called with rport_ptr->quota_lock_lhb2 locked. |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 727 | */ |
| 728 | static void post_resume_tx(struct msm_ipc_router_remote_port *rport_ptr, |
| 729 | struct rr_packet *pkt) |
| 730 | { |
| 731 | struct msm_ipc_resume_tx_port *rtx_port, *tmp_rtx_port; |
| 732 | struct msm_ipc_port *local_port; |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 733 | |
| 734 | list_for_each_entry_safe(rtx_port, tmp_rtx_port, |
| 735 | &rport_ptr->resume_tx_port_list, list) { |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 736 | local_port = |
| 737 | msm_ipc_router_lookup_local_port(rtx_port->port_id); |
Zaheerulla Meer | 51dc3a1 | 2013-05-08 19:27:27 +0530 | [diff] [blame] | 738 | if (local_port && local_port->notify) |
| 739 | local_port->notify(MSM_IPC_ROUTER_RESUME_TX, |
| 740 | local_port->priv); |
| 741 | else if (local_port) |
Karthikeyan Ramasubramanian | 6dbb00f | 2013-05-17 15:19:56 -0600 | [diff] [blame] | 742 | post_pkt_to_port(local_port, pkt, 1); |
Zaheerulla Meer | 51dc3a1 | 2013-05-08 19:27:27 +0530 | [diff] [blame] | 743 | else |
| 744 | pr_err("%s: Local Port %d not Found", |
| 745 | __func__, rtx_port->port_id); |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 746 | list_del(&rtx_port->list); |
| 747 | kfree(rtx_port); |
| 748 | } |
| 749 | } |
| 750 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 751 | /* Must be called with routing_table_lock_lha3 locked. */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 752 | static void msm_ipc_router_destroy_remote_port( |
| 753 | struct msm_ipc_router_remote_port *rport_ptr) |
| 754 | { |
| 755 | uint32_t node_id; |
| 756 | struct msm_ipc_routing_table_entry *rt_entry; |
| 757 | |
| 758 | if (!rport_ptr) |
| 759 | return; |
| 760 | |
| 761 | node_id = rport_ptr->node_id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 762 | rt_entry = lookup_routing_table(node_id); |
| 763 | if (!rt_entry) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 764 | pr_err("%s: Node %d is not up\n", __func__, node_id); |
| 765 | return; |
| 766 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 767 | down_write(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 768 | list_del(&rport_ptr->list); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 769 | up_write(&rt_entry->lock_lha4); |
| 770 | mutex_lock(&rport_ptr->quota_lock_lhb2); |
| 771 | msm_ipc_router_free_resume_tx_port(rport_ptr); |
| 772 | mutex_unlock(&rport_ptr->quota_lock_lhb2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 773 | kfree(rport_ptr); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 774 | return; |
| 775 | } |
| 776 | |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 777 | /** |
| 778 | * msm_ipc_router_lookup_server() - Lookup server information |
| 779 | * @service: Service ID of the server info to be looked up. |
| 780 | * @instance: Instance ID of the server info to be looked up. |
| 781 | * @node_id: Node/Processor ID in which the server is hosted. |
| 782 | * @port_id: Port ID within the node in which the server is hosted. |
| 783 | * |
| 784 | * @return: If found Pointer to server structure, else NULL. |
| 785 | * |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 786 | * Note1: Lock the server_list_lock_lha2 before accessing this function. |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 787 | * Note2: If the <node_id:port_id> are <0:0>, then the lookup is restricted |
| 788 | * to <service:instance>. Used only when a client wants to send a |
| 789 | * message to any QMI server. |
| 790 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 791 | static struct msm_ipc_server *msm_ipc_router_lookup_server( |
| 792 | uint32_t service, |
| 793 | uint32_t instance, |
| 794 | uint32_t node_id, |
| 795 | uint32_t port_id) |
| 796 | { |
| 797 | struct msm_ipc_server *server; |
| 798 | struct msm_ipc_server_port *server_port; |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 799 | int key = (service & (SRV_HASH_SIZE - 1)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 800 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 801 | list_for_each_entry(server, &server_list[key], list) { |
| 802 | if ((server->name.service != service) || |
| 803 | (server->name.instance != instance)) |
| 804 | continue; |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 805 | if ((node_id == 0) && (port_id == 0)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 806 | return server; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 807 | list_for_each_entry(server_port, &server->server_port_list, |
| 808 | list) { |
| 809 | if ((server_port->server_addr.node_id == node_id) && |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 810 | (server_port->server_addr.port_id == port_id)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 811 | return server; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 812 | } |
| 813 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 814 | return NULL; |
| 815 | } |
| 816 | |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 817 | static void dummy_release(struct device *dev) |
| 818 | { |
| 819 | } |
| 820 | |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 821 | /** |
| 822 | * msm_ipc_router_create_server() - Add server info to hash table |
| 823 | * @service: Service ID of the server info to be created. |
| 824 | * @instance: Instance ID of the server info to be created. |
| 825 | * @node_id: Node/Processor ID in which the server is hosted. |
| 826 | * @port_id: Port ID within the node in which the server is hosted. |
| 827 | * @xprt_info: XPRT through which the node hosting the server is reached. |
| 828 | * |
| 829 | * @return: Pointer to server structure on success, else NULL. |
| 830 | * |
| 831 | * This function adds the server info to the hash table. If the same |
| 832 | * server(i.e. <service_id:instance_id>) is hosted in different nodes, |
| 833 | * they are maintained as list of "server_port" under "server" structure. |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 834 | * Note: Lock the server_list_lock_lha2 before accessing this function. |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 835 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 836 | static struct msm_ipc_server *msm_ipc_router_create_server( |
| 837 | uint32_t service, |
| 838 | uint32_t instance, |
| 839 | uint32_t node_id, |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 840 | uint32_t port_id, |
| 841 | struct msm_ipc_router_xprt_info *xprt_info) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 842 | { |
| 843 | struct msm_ipc_server *server = NULL; |
| 844 | struct msm_ipc_server_port *server_port; |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 845 | int key = (service & (SRV_HASH_SIZE - 1)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 846 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 847 | list_for_each_entry(server, &server_list[key], list) { |
| 848 | if ((server->name.service == service) && |
| 849 | (server->name.instance == instance)) |
| 850 | goto create_srv_port; |
| 851 | } |
| 852 | |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 853 | server = kzalloc(sizeof(struct msm_ipc_server), GFP_KERNEL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 854 | if (!server) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 855 | pr_err("%s: Server allocation failed\n", __func__); |
| 856 | return NULL; |
| 857 | } |
| 858 | server->name.service = service; |
| 859 | server->name.instance = instance; |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 860 | server->synced_sec_rule = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 861 | INIT_LIST_HEAD(&server->server_port_list); |
| 862 | list_add_tail(&server->list, &server_list[key]); |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 863 | scnprintf(server->pdev_name, sizeof(server->pdev_name), |
| 864 | "QMI%08x:%08x", service, instance); |
| 865 | server->next_pdev_id = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 866 | |
| 867 | create_srv_port: |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 868 | server_port = kzalloc(sizeof(struct msm_ipc_server_port), GFP_KERNEL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 869 | if (!server_port) { |
| 870 | if (list_empty(&server->server_port_list)) { |
| 871 | list_del(&server->list); |
| 872 | kfree(server); |
| 873 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 874 | pr_err("%s: Server Port allocation failed\n", __func__); |
| 875 | return NULL; |
| 876 | } |
| 877 | server_port->server_addr.node_id = node_id; |
| 878 | server_port->server_addr.port_id = port_id; |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 879 | server_port->xprt_info = xprt_info; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 880 | list_add_tail(&server_port->list, &server->server_port_list); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 881 | |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 882 | server_port->pdev.name = server->pdev_name; |
| 883 | server_port->pdev.id = server->next_pdev_id++; |
| 884 | server_port->pdev.dev.release = dummy_release; |
| 885 | platform_device_register(&server_port->pdev); |
| 886 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 887 | return server; |
| 888 | } |
| 889 | |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 890 | /** |
| 891 | * msm_ipc_router_destroy_server() - Remove server info from hash table |
| 892 | * @server: Server info to be removed. |
| 893 | * @node_id: Node/Processor ID in which the server is hosted. |
| 894 | * @port_id: Port ID within the node in which the server is hosted. |
| 895 | * |
| 896 | * This function removes the server_port identified using <node_id:port_id> |
| 897 | * from the server structure. If the server_port list under server structure |
| 898 | * is empty after removal, then remove the server structure from the server |
| 899 | * hash table. |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 900 | * Note: Lock the server_list_lock_lha2 before accessing this function. |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 901 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 902 | static void msm_ipc_router_destroy_server(struct msm_ipc_server *server, |
| 903 | uint32_t node_id, uint32_t port_id) |
| 904 | { |
| 905 | struct msm_ipc_server_port *server_port; |
| 906 | |
| 907 | if (!server) |
| 908 | return; |
| 909 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 910 | list_for_each_entry(server_port, &server->server_port_list, list) { |
| 911 | if ((server_port->server_addr.node_id == node_id) && |
| 912 | (server_port->server_addr.port_id == port_id)) |
| 913 | break; |
| 914 | } |
| 915 | if (server_port) { |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 916 | platform_device_unregister(&server_port->pdev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 917 | list_del(&server_port->list); |
| 918 | kfree(server_port); |
| 919 | } |
| 920 | if (list_empty(&server->server_port_list)) { |
| 921 | list_del(&server->list); |
| 922 | kfree(server); |
| 923 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 924 | return; |
| 925 | } |
| 926 | |
| 927 | static int msm_ipc_router_send_control_msg( |
| 928 | struct msm_ipc_router_xprt_info *xprt_info, |
| 929 | union rr_control_msg *msg) |
| 930 | { |
| 931 | struct rr_packet *pkt; |
| 932 | struct sk_buff *ipc_rtr_pkt; |
| 933 | struct rr_header *hdr; |
| 934 | int pkt_size; |
| 935 | void *data; |
| 936 | struct sk_buff_head *pkt_fragment_q; |
| 937 | int ret; |
| 938 | |
| 939 | if (!xprt_info || ((msg->cmd != IPC_ROUTER_CTRL_CMD_HELLO) && |
| 940 | !xprt_info->initialized)) { |
| 941 | pr_err("%s: xprt_info not initialized\n", __func__); |
| 942 | return -EINVAL; |
| 943 | } |
| 944 | |
| 945 | if (xprt_info->remote_node_id == IPC_ROUTER_NID_LOCAL) |
| 946 | return 0; |
| 947 | |
| 948 | pkt = kzalloc(sizeof(struct rr_packet), GFP_KERNEL); |
| 949 | if (!pkt) { |
| 950 | pr_err("%s: pkt alloc failed\n", __func__); |
| 951 | return -ENOMEM; |
| 952 | } |
| 953 | |
| 954 | pkt_fragment_q = kmalloc(sizeof(struct sk_buff_head), GFP_KERNEL); |
| 955 | if (!pkt_fragment_q) { |
| 956 | pr_err("%s: pkt_fragment_q alloc failed\n", __func__); |
| 957 | kfree(pkt); |
| 958 | return -ENOMEM; |
| 959 | } |
| 960 | skb_queue_head_init(pkt_fragment_q); |
| 961 | |
| 962 | pkt_size = IPC_ROUTER_HDR_SIZE + sizeof(*msg); |
| 963 | ipc_rtr_pkt = alloc_skb(pkt_size, GFP_KERNEL); |
| 964 | if (!ipc_rtr_pkt) { |
| 965 | pr_err("%s: ipc_rtr_pkt alloc failed\n", __func__); |
| 966 | kfree(pkt_fragment_q); |
| 967 | kfree(pkt); |
| 968 | return -ENOMEM; |
| 969 | } |
| 970 | |
| 971 | skb_reserve(ipc_rtr_pkt, IPC_ROUTER_HDR_SIZE); |
| 972 | data = skb_put(ipc_rtr_pkt, sizeof(*msg)); |
| 973 | memcpy(data, msg, sizeof(*msg)); |
| 974 | hdr = (struct rr_header *)skb_push(ipc_rtr_pkt, IPC_ROUTER_HDR_SIZE); |
| 975 | if (!hdr) { |
| 976 | pr_err("%s: skb_push failed\n", __func__); |
| 977 | kfree_skb(ipc_rtr_pkt); |
| 978 | kfree(pkt_fragment_q); |
| 979 | kfree(pkt); |
| 980 | return -ENOMEM; |
| 981 | } |
| 982 | |
| 983 | hdr->version = IPC_ROUTER_VERSION; |
| 984 | hdr->type = msg->cmd; |
| 985 | hdr->src_node_id = IPC_ROUTER_NID_LOCAL; |
| 986 | hdr->src_port_id = IPC_ROUTER_ADDRESS; |
| 987 | hdr->confirm_rx = 0; |
| 988 | hdr->size = sizeof(*msg); |
| 989 | hdr->dst_node_id = xprt_info->remote_node_id; |
| 990 | hdr->dst_port_id = IPC_ROUTER_ADDRESS; |
| 991 | skb_queue_tail(pkt_fragment_q, ipc_rtr_pkt); |
| 992 | pkt->pkt_fragment_q = pkt_fragment_q; |
| 993 | pkt->length = pkt_size; |
| 994 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 995 | mutex_lock(&xprt_info->tx_lock_lhb2); |
Karthikeyan Ramasubramanian | 8cec592 | 2012-02-16 17:41:58 -0700 | [diff] [blame] | 996 | ret = xprt_info->xprt->write(pkt, pkt_size, xprt_info->xprt); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 997 | mutex_unlock(&xprt_info->tx_lock_lhb2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 998 | |
| 999 | release_pkt(pkt); |
| 1000 | return ret; |
| 1001 | } |
| 1002 | |
Karthikeyan Ramasubramanian | a2b7fdb | 2012-10-23 13:12:44 -0600 | [diff] [blame] | 1003 | static int msm_ipc_router_send_server_list(uint32_t node_id, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1004 | struct msm_ipc_router_xprt_info *xprt_info) |
| 1005 | { |
| 1006 | union rr_control_msg ctl; |
| 1007 | struct msm_ipc_server *server; |
| 1008 | struct msm_ipc_server_port *server_port; |
| 1009 | int i; |
| 1010 | |
| 1011 | if (!xprt_info || !xprt_info->initialized) { |
| 1012 | pr_err("%s: Xprt info not initialized\n", __func__); |
| 1013 | return -EINVAL; |
| 1014 | } |
| 1015 | |
| 1016 | ctl.cmd = IPC_ROUTER_CTRL_CMD_NEW_SERVER; |
| 1017 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1018 | for (i = 0; i < SRV_HASH_SIZE; i++) { |
| 1019 | list_for_each_entry(server, &server_list[i], list) { |
| 1020 | ctl.srv.service = server->name.service; |
| 1021 | ctl.srv.instance = server->name.instance; |
| 1022 | list_for_each_entry(server_port, |
| 1023 | &server->server_port_list, list) { |
Karthikeyan Ramasubramanian | a2b7fdb | 2012-10-23 13:12:44 -0600 | [diff] [blame] | 1024 | if (server_port->server_addr.node_id != |
| 1025 | node_id) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1026 | continue; |
| 1027 | |
| 1028 | ctl.srv.node_id = |
| 1029 | server_port->server_addr.node_id; |
| 1030 | ctl.srv.port_id = |
| 1031 | server_port->server_addr.port_id; |
| 1032 | msm_ipc_router_send_control_msg(xprt_info, |
| 1033 | &ctl); |
| 1034 | } |
| 1035 | } |
| 1036 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1037 | |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
| 1041 | #if defined(DEBUG) |
| 1042 | static char *type_to_str(int i) |
| 1043 | { |
| 1044 | switch (i) { |
| 1045 | case IPC_ROUTER_CTRL_CMD_DATA: |
| 1046 | return "data "; |
| 1047 | case IPC_ROUTER_CTRL_CMD_HELLO: |
| 1048 | return "hello "; |
| 1049 | case IPC_ROUTER_CTRL_CMD_BYE: |
| 1050 | return "bye "; |
| 1051 | case IPC_ROUTER_CTRL_CMD_NEW_SERVER: |
| 1052 | return "new_srvr"; |
| 1053 | case IPC_ROUTER_CTRL_CMD_REMOVE_SERVER: |
| 1054 | return "rmv_srvr"; |
| 1055 | case IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT: |
| 1056 | return "rmv_clnt"; |
| 1057 | case IPC_ROUTER_CTRL_CMD_RESUME_TX: |
| 1058 | return "resum_tx"; |
| 1059 | case IPC_ROUTER_CTRL_CMD_EXIT: |
| 1060 | return "cmd_exit"; |
| 1061 | default: |
| 1062 | return "invalid"; |
| 1063 | } |
| 1064 | } |
| 1065 | #endif |
| 1066 | |
| 1067 | static int broadcast_ctl_msg_locally(union rr_control_msg *msg) |
| 1068 | { |
| 1069 | struct rr_packet *pkt; |
| 1070 | struct sk_buff *ipc_rtr_pkt; |
| 1071 | struct rr_header *hdr; |
| 1072 | int pkt_size; |
| 1073 | void *data; |
| 1074 | struct sk_buff_head *pkt_fragment_q; |
| 1075 | int ret; |
| 1076 | |
| 1077 | pkt = kzalloc(sizeof(struct rr_packet), GFP_KERNEL); |
| 1078 | if (!pkt) { |
| 1079 | pr_err("%s: pkt alloc failed\n", __func__); |
| 1080 | return -ENOMEM; |
| 1081 | } |
| 1082 | |
| 1083 | pkt_fragment_q = kmalloc(sizeof(struct sk_buff_head), GFP_KERNEL); |
| 1084 | if (!pkt_fragment_q) { |
| 1085 | pr_err("%s: pkt_fragment_q alloc failed\n", __func__); |
| 1086 | kfree(pkt); |
| 1087 | return -ENOMEM; |
| 1088 | } |
| 1089 | skb_queue_head_init(pkt_fragment_q); |
| 1090 | |
| 1091 | pkt_size = IPC_ROUTER_HDR_SIZE + sizeof(*msg); |
| 1092 | ipc_rtr_pkt = alloc_skb(pkt_size, GFP_KERNEL); |
| 1093 | if (!ipc_rtr_pkt) { |
| 1094 | pr_err("%s: ipc_rtr_pkt alloc failed\n", __func__); |
| 1095 | kfree(pkt_fragment_q); |
| 1096 | kfree(pkt); |
| 1097 | return -ENOMEM; |
| 1098 | } |
| 1099 | |
| 1100 | skb_reserve(ipc_rtr_pkt, IPC_ROUTER_HDR_SIZE); |
| 1101 | data = skb_put(ipc_rtr_pkt, sizeof(*msg)); |
| 1102 | memcpy(data, msg, sizeof(*msg)); |
| 1103 | hdr = (struct rr_header *)skb_push(ipc_rtr_pkt, IPC_ROUTER_HDR_SIZE); |
| 1104 | if (!hdr) { |
| 1105 | pr_err("%s: skb_push failed\n", __func__); |
| 1106 | kfree_skb(ipc_rtr_pkt); |
| 1107 | kfree(pkt_fragment_q); |
| 1108 | kfree(pkt); |
| 1109 | return -ENOMEM; |
| 1110 | } |
| 1111 | hdr->version = IPC_ROUTER_VERSION; |
| 1112 | hdr->type = msg->cmd; |
| 1113 | hdr->src_node_id = IPC_ROUTER_NID_LOCAL; |
| 1114 | hdr->src_port_id = IPC_ROUTER_ADDRESS; |
| 1115 | hdr->confirm_rx = 0; |
| 1116 | hdr->size = sizeof(*msg); |
| 1117 | hdr->dst_node_id = IPC_ROUTER_NID_LOCAL; |
| 1118 | hdr->dst_port_id = IPC_ROUTER_ADDRESS; |
| 1119 | skb_queue_tail(pkt_fragment_q, ipc_rtr_pkt); |
| 1120 | pkt->pkt_fragment_q = pkt_fragment_q; |
| 1121 | pkt->length = pkt_size; |
| 1122 | |
| 1123 | ret = post_control_ports(pkt); |
| 1124 | release_pkt(pkt); |
| 1125 | return ret; |
| 1126 | } |
| 1127 | |
| 1128 | static int broadcast_ctl_msg(union rr_control_msg *ctl) |
| 1129 | { |
| 1130 | struct msm_ipc_router_xprt_info *xprt_info; |
| 1131 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1132 | down_read(&xprt_info_list_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1133 | list_for_each_entry(xprt_info, &xprt_info_list, list) { |
| 1134 | msm_ipc_router_send_control_msg(xprt_info, ctl); |
| 1135 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1136 | up_read(&xprt_info_list_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1137 | |
| 1138 | return 0; |
| 1139 | } |
| 1140 | |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1141 | static int relay_ctl_msg(struct msm_ipc_router_xprt_info *xprt_info, |
| 1142 | union rr_control_msg *ctl) |
| 1143 | { |
| 1144 | struct msm_ipc_router_xprt_info *fwd_xprt_info; |
| 1145 | |
| 1146 | if (!xprt_info || !ctl) |
| 1147 | return -EINVAL; |
| 1148 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1149 | down_read(&xprt_info_list_lock_lha5); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1150 | list_for_each_entry(fwd_xprt_info, &xprt_info_list, list) { |
| 1151 | if (xprt_info->xprt->link_id != fwd_xprt_info->xprt->link_id) |
| 1152 | msm_ipc_router_send_control_msg(fwd_xprt_info, ctl); |
| 1153 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1154 | up_read(&xprt_info_list_lock_lha5); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1155 | |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1159 | static int relay_msg(struct msm_ipc_router_xprt_info *xprt_info, |
| 1160 | struct rr_packet *pkt) |
| 1161 | { |
| 1162 | struct msm_ipc_router_xprt_info *fwd_xprt_info; |
| 1163 | |
| 1164 | if (!xprt_info || !pkt) |
| 1165 | return -EINVAL; |
| 1166 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1167 | down_read(&xprt_info_list_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1168 | list_for_each_entry(fwd_xprt_info, &xprt_info_list, list) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1169 | mutex_lock(&fwd_xprt_info->tx_lock_lhb2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1170 | if (xprt_info->xprt->link_id != fwd_xprt_info->xprt->link_id) |
Karthikeyan Ramasubramanian | 8cec592 | 2012-02-16 17:41:58 -0700 | [diff] [blame] | 1171 | fwd_xprt_info->xprt->write(pkt, pkt->length, |
| 1172 | fwd_xprt_info->xprt); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1173 | mutex_unlock(&fwd_xprt_info->tx_lock_lhb2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1174 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1175 | up_read(&xprt_info_list_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | static int forward_msg(struct msm_ipc_router_xprt_info *xprt_info, |
| 1180 | struct rr_packet *pkt) |
| 1181 | { |
| 1182 | uint32_t dst_node_id; |
| 1183 | struct sk_buff *head_pkt; |
| 1184 | struct rr_header *hdr; |
| 1185 | struct msm_ipc_router_xprt_info *fwd_xprt_info; |
| 1186 | struct msm_ipc_routing_table_entry *rt_entry; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1187 | int ret = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1188 | |
| 1189 | if (!xprt_info || !pkt) |
| 1190 | return -EINVAL; |
| 1191 | |
| 1192 | head_pkt = skb_peek(pkt->pkt_fragment_q); |
| 1193 | if (!head_pkt) |
| 1194 | return -EINVAL; |
| 1195 | |
| 1196 | hdr = (struct rr_header *)head_pkt->data; |
| 1197 | dst_node_id = hdr->dst_node_id; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1198 | down_read(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1199 | rt_entry = lookup_routing_table(dst_node_id); |
| 1200 | if (!(rt_entry) || !(rt_entry->xprt_info)) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1201 | up_read(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1202 | pr_err("%s: Routing table not initialized\n", __func__); |
| 1203 | return -ENODEV; |
| 1204 | } |
| 1205 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1206 | down_read(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1207 | fwd_xprt_info = rt_entry->xprt_info; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1208 | if (xprt_info->remote_node_id == fwd_xprt_info->remote_node_id) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1209 | pr_err("%s: Discarding Command to route back\n", __func__); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1210 | ret = -EINVAL; |
| 1211 | goto fwd_msg_out; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | if (xprt_info->xprt->link_id == fwd_xprt_info->xprt->link_id) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1215 | pr_err("%s: DST in the same cluster\n", __func__); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1216 | goto fwd_msg_out; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1217 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1218 | mutex_lock(&fwd_xprt_info->tx_lock_lhb2); |
Karthikeyan Ramasubramanian | 8cec592 | 2012-02-16 17:41:58 -0700 | [diff] [blame] | 1219 | fwd_xprt_info->xprt->write(pkt, pkt->length, fwd_xprt_info->xprt); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1220 | mutex_unlock(&fwd_xprt_info->tx_lock_lhb2); |
| 1221 | fwd_msg_out: |
| 1222 | up_read(&rt_entry->lock_lha4); |
| 1223 | up_read(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1224 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1225 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
Karthikeyan Ramasubramanian | 96cced7 | 2013-05-02 17:25:54 -0600 | [diff] [blame] | 1228 | static int msm_ipc_router_send_remove_client(struct comm_mode_info *mode_info, |
| 1229 | uint32_t node_id, uint32_t port_id) |
| 1230 | { |
| 1231 | union rr_control_msg msg; |
| 1232 | struct msm_ipc_router_xprt_info *tmp_xprt_info; |
| 1233 | int mode; |
| 1234 | void *xprt_info; |
| 1235 | int rc = 0; |
| 1236 | |
| 1237 | if (!mode_info) { |
| 1238 | pr_err("%s: NULL mode_info\n", __func__); |
| 1239 | return -EINVAL; |
| 1240 | } |
| 1241 | mode = mode_info->mode; |
| 1242 | xprt_info = mode_info->xprt_info; |
| 1243 | |
| 1244 | msg.cmd = IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT; |
| 1245 | msg.cli.node_id = node_id; |
| 1246 | msg.cli.port_id = port_id; |
| 1247 | |
| 1248 | if ((mode == SINGLE_LINK_MODE) && xprt_info) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1249 | down_read(&xprt_info_list_lock_lha5); |
Karthikeyan Ramasubramanian | 96cced7 | 2013-05-02 17:25:54 -0600 | [diff] [blame] | 1250 | list_for_each_entry(tmp_xprt_info, &xprt_info_list, list) { |
| 1251 | if (tmp_xprt_info != xprt_info) |
| 1252 | continue; |
| 1253 | msm_ipc_router_send_control_msg(tmp_xprt_info, &msg); |
| 1254 | break; |
| 1255 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1256 | up_read(&xprt_info_list_lock_lha5); |
Karthikeyan Ramasubramanian | 96cced7 | 2013-05-02 17:25:54 -0600 | [diff] [blame] | 1257 | } else if ((mode == SINGLE_LINK_MODE) && !xprt_info) { |
| 1258 | broadcast_ctl_msg_locally(&msg); |
| 1259 | } else if (mode == MULTI_LINK_MODE) { |
| 1260 | broadcast_ctl_msg(&msg); |
| 1261 | broadcast_ctl_msg_locally(&msg); |
| 1262 | } else if (mode != NULL_MODE) { |
| 1263 | pr_err("%s: Invalid mode(%d) + xprt_inf(%p) for %08x:%08x\n", |
| 1264 | __func__, mode, xprt_info, node_id, port_id); |
| 1265 | rc = -EINVAL; |
| 1266 | } |
| 1267 | return rc; |
| 1268 | } |
| 1269 | |
| 1270 | static void update_comm_mode_info(struct comm_mode_info *mode_info, |
| 1271 | struct msm_ipc_router_xprt_info *xprt_info) |
| 1272 | { |
| 1273 | if (!mode_info) { |
| 1274 | pr_err("%s: NULL mode_info\n", __func__); |
| 1275 | return; |
| 1276 | } |
| 1277 | |
| 1278 | if (mode_info->mode == NULL_MODE) { |
| 1279 | mode_info->xprt_info = xprt_info; |
| 1280 | mode_info->mode = SINGLE_LINK_MODE; |
| 1281 | } else if (mode_info->mode == SINGLE_LINK_MODE && |
| 1282 | mode_info->xprt_info != xprt_info) { |
| 1283 | mode_info->mode = MULTI_LINK_MODE; |
| 1284 | } |
| 1285 | |
| 1286 | return; |
| 1287 | } |
| 1288 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1289 | static void cleanup_rmt_server(struct msm_ipc_router_xprt_info *xprt_info, |
| 1290 | struct msm_ipc_router_remote_port *rport_ptr) |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1291 | { |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1292 | union rr_control_msg ctl; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1293 | struct msm_ipc_server *server = rport_ptr->server; |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1294 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1295 | D("Remove server %08x:%08x - %08x:%08x", |
| 1296 | server->name.service, server->name.instance, |
| 1297 | rport_ptr->node_id, rport_ptr->port_id); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1298 | ctl.cmd = IPC_ROUTER_CTRL_CMD_REMOVE_SERVER; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1299 | ctl.srv.service = server->name.service; |
| 1300 | ctl.srv.instance = server->name.instance; |
| 1301 | ctl.srv.node_id = rport_ptr->node_id; |
| 1302 | ctl.srv.port_id = rport_ptr->port_id; |
| 1303 | relay_ctl_msg(xprt_info, &ctl); |
| 1304 | broadcast_ctl_msg_locally(&ctl); |
| 1305 | msm_ipc_router_destroy_server(server, |
| 1306 | rport_ptr->node_id, rport_ptr->port_id); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1307 | } |
| 1308 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1309 | static void cleanup_rmt_ports(struct msm_ipc_router_xprt_info *xprt_info, |
| 1310 | struct msm_ipc_routing_table_entry *rt_entry) |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1311 | { |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1312 | struct msm_ipc_router_remote_port *rport_ptr, *tmp_rport_ptr; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1313 | union rr_control_msg ctl; |
| 1314 | int j; |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1315 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1316 | for (j = 0; j < RP_HASH_SIZE; j++) { |
| 1317 | list_for_each_entry_safe(rport_ptr, tmp_rport_ptr, |
| 1318 | &rt_entry->remote_port_list[j], list) { |
| 1319 | list_del(&rport_ptr->list); |
| 1320 | mutex_lock(&rport_ptr->quota_lock_lhb2); |
| 1321 | msm_ipc_router_free_resume_tx_port(rport_ptr); |
| 1322 | mutex_unlock(&rport_ptr->quota_lock_lhb2); |
| 1323 | |
| 1324 | if (rport_ptr->server) |
| 1325 | cleanup_rmt_server(xprt_info, rport_ptr); |
| 1326 | |
| 1327 | ctl.cmd = IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT; |
| 1328 | ctl.cli.node_id = rport_ptr->node_id; |
| 1329 | ctl.cli.port_id = rport_ptr->port_id; |
| 1330 | relay_ctl_msg(xprt_info, &ctl); |
| 1331 | broadcast_ctl_msg_locally(&ctl); |
| 1332 | kfree(rport_ptr); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1333 | } |
| 1334 | } |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | static void msm_ipc_cleanup_routing_table( |
| 1338 | struct msm_ipc_router_xprt_info *xprt_info) |
| 1339 | { |
| 1340 | int i; |
| 1341 | struct msm_ipc_routing_table_entry *rt_entry; |
| 1342 | |
| 1343 | if (!xprt_info) { |
| 1344 | pr_err("%s: Invalid xprt_info\n", __func__); |
| 1345 | return; |
| 1346 | } |
| 1347 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1348 | down_write(&server_list_lock_lha2); |
| 1349 | down_write(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1350 | for (i = 0; i < RT_HASH_SIZE; i++) { |
| 1351 | list_for_each_entry(rt_entry, &routing_table[i], list) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1352 | down_write(&rt_entry->lock_lha4); |
| 1353 | if (rt_entry->xprt_info != xprt_info) { |
| 1354 | up_write(&rt_entry->lock_lha4); |
| 1355 | continue; |
| 1356 | } |
| 1357 | cleanup_rmt_ports(xprt_info, rt_entry); |
| 1358 | rt_entry->xprt_info = NULL; |
| 1359 | up_write(&rt_entry->lock_lha4); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1360 | } |
| 1361 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1362 | up_write(&routing_table_lock_lha3); |
| 1363 | up_write(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1364 | } |
| 1365 | |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 1366 | /** |
| 1367 | * sync_sec_rule() - Synchrnoize the security rule into the server structure |
| 1368 | * @server: Server structure where the rule has to be synchronized. |
| 1369 | * @rule: Security tule to be synchronized. |
| 1370 | * |
| 1371 | * This function is used to update the server structure with the security |
| 1372 | * rule configured for the <service:instance> corresponding to that server. |
| 1373 | */ |
| 1374 | static void sync_sec_rule(struct msm_ipc_server *server, void *rule) |
| 1375 | { |
| 1376 | struct msm_ipc_server_port *server_port; |
| 1377 | struct msm_ipc_router_remote_port *rport_ptr = NULL; |
| 1378 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1379 | down_read(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 1380 | list_for_each_entry(server_port, &server->server_port_list, list) { |
| 1381 | rport_ptr = msm_ipc_router_lookup_remote_port( |
| 1382 | server_port->server_addr.node_id, |
| 1383 | server_port->server_addr.port_id); |
| 1384 | if (!rport_ptr) |
| 1385 | continue; |
| 1386 | rport_ptr->sec_rule = rule; |
| 1387 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1388 | up_read(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 1389 | server->synced_sec_rule = 1; |
| 1390 | } |
| 1391 | |
| 1392 | /** |
| 1393 | * msm_ipc_sync_sec_rule() - Sync the security rule to the service |
| 1394 | * @service: Service for which the rule has to be synchronized. |
| 1395 | * @instance: Instance for which the rule has to be synchronized. |
| 1396 | * @rule: Security rule to be synchronized. |
| 1397 | * |
| 1398 | * This function is used to syncrhonize the security rule with the server |
| 1399 | * hash table, if the user-space script configures the rule after the service |
| 1400 | * has come up. This function is used to synchronize the security rule to a |
| 1401 | * specific service and optionally a specific instance. |
| 1402 | */ |
| 1403 | void msm_ipc_sync_sec_rule(uint32_t service, uint32_t instance, void *rule) |
| 1404 | { |
| 1405 | int key = (service & (SRV_HASH_SIZE - 1)); |
| 1406 | struct msm_ipc_server *server; |
| 1407 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1408 | down_write(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 1409 | list_for_each_entry(server, &server_list[key], list) { |
| 1410 | if (server->name.service != service) |
| 1411 | continue; |
| 1412 | |
| 1413 | if (server->name.instance != instance && |
| 1414 | instance != ALL_INSTANCE) |
| 1415 | continue; |
| 1416 | |
| 1417 | /* |
| 1418 | * If the rule applies to all instances and if the specific |
| 1419 | * instance of a service has a rule synchronized already, |
| 1420 | * do not apply the rule for that specific instance. |
| 1421 | */ |
| 1422 | if (instance == ALL_INSTANCE && server->synced_sec_rule) |
| 1423 | continue; |
| 1424 | |
| 1425 | sync_sec_rule(server, rule); |
| 1426 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1427 | up_write(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | /** |
| 1431 | * msm_ipc_sync_default_sec_rule() - Default security rule to all services |
| 1432 | * @rule: Security rule to be synchronized. |
| 1433 | * |
| 1434 | * This function is used to syncrhonize the security rule with the server |
| 1435 | * hash table, if the user-space script configures the rule after the service |
| 1436 | * has come up. This function is used to synchronize the security rule that |
| 1437 | * applies to all services, if the concerned service do not have any rule |
| 1438 | * defined. |
| 1439 | */ |
| 1440 | void msm_ipc_sync_default_sec_rule(void *rule) |
| 1441 | { |
| 1442 | int key; |
| 1443 | struct msm_ipc_server *server; |
| 1444 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1445 | down_write(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 1446 | for (key = 0; key < SRV_HASH_SIZE; key++) { |
| 1447 | list_for_each_entry(server, &server_list[key], list) { |
| 1448 | if (server->synced_sec_rule) |
| 1449 | continue; |
| 1450 | |
| 1451 | sync_sec_rule(server, rule); |
| 1452 | } |
| 1453 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1454 | up_write(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 1455 | } |
| 1456 | |
Karthikeyan Ramasubramanian | a2b7fdb | 2012-10-23 13:12:44 -0600 | [diff] [blame] | 1457 | static int process_hello_msg(struct msm_ipc_router_xprt_info *xprt_info, |
| 1458 | struct rr_header *hdr) |
| 1459 | { |
| 1460 | int i, rc = 0; |
| 1461 | union rr_control_msg ctl; |
| 1462 | struct msm_ipc_routing_table_entry *rt_entry; |
| 1463 | |
| 1464 | if (!hdr) |
| 1465 | return -EINVAL; |
| 1466 | |
| 1467 | RR("o HELLO NID %d\n", hdr->src_node_id); |
| 1468 | |
| 1469 | xprt_info->remote_node_id = hdr->src_node_id; |
| 1470 | /* |
| 1471 | * Find the entry from Routing Table corresponding to Node ID. |
| 1472 | * Under SSR, an entry will be found. When the system boots up |
| 1473 | * for the 1st time, an entry will not be found and hence allocate |
| 1474 | * an entry. Update the entry with the Node ID that it corresponds |
| 1475 | * to and the XPRT through which it can be reached. |
| 1476 | */ |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1477 | down_write(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | a2b7fdb | 2012-10-23 13:12:44 -0600 | [diff] [blame] | 1478 | rt_entry = lookup_routing_table(hdr->src_node_id); |
| 1479 | if (!rt_entry) { |
| 1480 | rt_entry = alloc_routing_table_entry(hdr->src_node_id); |
| 1481 | if (!rt_entry) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1482 | up_write(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | a2b7fdb | 2012-10-23 13:12:44 -0600 | [diff] [blame] | 1483 | pr_err("%s: rt_entry allocation failed\n", __func__); |
| 1484 | return -ENOMEM; |
| 1485 | } |
| 1486 | add_routing_table_entry(rt_entry); |
| 1487 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1488 | down_write(&rt_entry->lock_lha4); |
Karthikeyan Ramasubramanian | a2b7fdb | 2012-10-23 13:12:44 -0600 | [diff] [blame] | 1489 | rt_entry->neighbor_node_id = xprt_info->remote_node_id; |
| 1490 | rt_entry->xprt_info = xprt_info; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1491 | up_write(&rt_entry->lock_lha4); |
| 1492 | up_write(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | a2b7fdb | 2012-10-23 13:12:44 -0600 | [diff] [blame] | 1493 | |
| 1494 | /* Send a reply HELLO message */ |
| 1495 | memset(&ctl, 0, sizeof(ctl)); |
| 1496 | ctl.cmd = IPC_ROUTER_CTRL_CMD_HELLO; |
| 1497 | rc = msm_ipc_router_send_control_msg(xprt_info, &ctl); |
| 1498 | if (rc < 0) { |
| 1499 | pr_err("%s: Error sending reply HELLO message\n", __func__); |
| 1500 | return rc; |
| 1501 | } |
| 1502 | xprt_info->initialized = 1; |
| 1503 | |
| 1504 | /* |
| 1505 | * Send list of servers from the local node and from nodes |
| 1506 | * outside the mesh network in which this XPRT is part of. |
| 1507 | */ |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1508 | down_read(&server_list_lock_lha2); |
| 1509 | down_read(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | a2b7fdb | 2012-10-23 13:12:44 -0600 | [diff] [blame] | 1510 | for (i = 0; i < RT_HASH_SIZE; i++) { |
| 1511 | list_for_each_entry(rt_entry, &routing_table[i], list) { |
| 1512 | if ((rt_entry->node_id != IPC_ROUTER_NID_LOCAL) && |
Karthikeyan Ramasubramanian | c4c0aaa | 2013-01-30 14:17:57 -0700 | [diff] [blame] | 1513 | (!rt_entry->xprt_info || |
| 1514 | (rt_entry->xprt_info->xprt->link_id == |
| 1515 | xprt_info->xprt->link_id))) |
Karthikeyan Ramasubramanian | a2b7fdb | 2012-10-23 13:12:44 -0600 | [diff] [blame] | 1516 | continue; |
| 1517 | rc = msm_ipc_router_send_server_list(rt_entry->node_id, |
| 1518 | xprt_info); |
| 1519 | if (rc < 0) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1520 | up_read(&routing_table_lock_lha3); |
| 1521 | up_read(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | a2b7fdb | 2012-10-23 13:12:44 -0600 | [diff] [blame] | 1522 | return rc; |
| 1523 | } |
| 1524 | } |
| 1525 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1526 | up_read(&routing_table_lock_lha3); |
| 1527 | up_read(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | a2b7fdb | 2012-10-23 13:12:44 -0600 | [diff] [blame] | 1528 | RR("HELLO message processed\n"); |
| 1529 | return rc; |
| 1530 | } |
| 1531 | |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1532 | static int process_resume_tx_msg(union rr_control_msg *msg, |
| 1533 | struct rr_packet *pkt) |
| 1534 | { |
| 1535 | struct msm_ipc_router_remote_port *rport_ptr; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1536 | int ret = 0; |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1537 | |
| 1538 | RR("o RESUME_TX id=%d:%08x\n", msg->cli.node_id, msg->cli.port_id); |
| 1539 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1540 | down_read(&local_ports_lock_lha2); |
| 1541 | down_read(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1542 | rport_ptr = msm_ipc_router_lookup_remote_port(msg->cli.node_id, |
| 1543 | msg->cli.port_id); |
| 1544 | if (!rport_ptr) { |
| 1545 | pr_err("%s: Unable to resume client\n", __func__); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1546 | ret = -ENODEV; |
| 1547 | goto prtm_out; |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1548 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1549 | mutex_lock(&rport_ptr->quota_lock_lhb2); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1550 | rport_ptr->tx_quota_cnt = 0; |
| 1551 | post_resume_tx(rport_ptr, pkt); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1552 | mutex_unlock(&rport_ptr->quota_lock_lhb2); |
| 1553 | prtm_out: |
| 1554 | up_read(&routing_table_lock_lha3); |
| 1555 | up_read(&local_ports_lock_lha2); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1556 | return 0; |
| 1557 | } |
| 1558 | |
| 1559 | static int process_new_server_msg(struct msm_ipc_router_xprt_info *xprt_info, |
| 1560 | union rr_control_msg *msg, struct rr_packet *pkt) |
| 1561 | { |
| 1562 | struct msm_ipc_routing_table_entry *rt_entry; |
| 1563 | struct msm_ipc_server *server; |
| 1564 | struct msm_ipc_router_remote_port *rport_ptr; |
| 1565 | |
| 1566 | if (msg->srv.instance == 0) { |
| 1567 | pr_err("%s: Server %08x create rejected, version = 0\n", |
| 1568 | __func__, msg->srv.service); |
| 1569 | return -EINVAL; |
| 1570 | } |
| 1571 | |
| 1572 | RR("o NEW_SERVER id=%d:%08x service=%08x:%08x\n", msg->srv.node_id, |
| 1573 | msg->srv.port_id, msg->srv.service, msg->srv.instance); |
| 1574 | /* |
| 1575 | * Find the entry from Routing Table corresponding to Node ID. |
| 1576 | * Under SSR, an entry will be found. When the subsystem hosting |
| 1577 | * service is not adjacent, an entry will not be found and hence |
| 1578 | * allocate an entry. Update the entry with the Node ID that it |
| 1579 | * corresponds to and the XPRT through which it can be reached. |
| 1580 | */ |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1581 | down_write(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1582 | rt_entry = lookup_routing_table(msg->srv.node_id); |
| 1583 | if (!rt_entry) { |
| 1584 | rt_entry = alloc_routing_table_entry(msg->srv.node_id); |
| 1585 | if (!rt_entry) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1586 | up_write(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1587 | pr_err("%s: rt_entry allocation failed\n", __func__); |
| 1588 | return -ENOMEM; |
| 1589 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1590 | down_write(&rt_entry->lock_lha4); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1591 | rt_entry->neighbor_node_id = xprt_info->remote_node_id; |
| 1592 | rt_entry->xprt_info = xprt_info; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1593 | up_write(&rt_entry->lock_lha4); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1594 | add_routing_table_entry(rt_entry); |
| 1595 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1596 | up_write(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1597 | |
| 1598 | /* |
| 1599 | * If the service does not exist already in the database, create and |
| 1600 | * store the service info. Create a remote port structure in which |
| 1601 | * the service is hosted and cache the security rule for the service |
| 1602 | * in that remote port structure. |
| 1603 | */ |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1604 | down_write(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1605 | server = msm_ipc_router_lookup_server(msg->srv.service, |
| 1606 | msg->srv.instance, msg->srv.node_id, msg->srv.port_id); |
| 1607 | if (!server) { |
| 1608 | server = msm_ipc_router_create_server( |
| 1609 | msg->srv.service, msg->srv.instance, |
| 1610 | msg->srv.node_id, msg->srv.port_id, xprt_info); |
| 1611 | if (!server) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1612 | up_write(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1613 | pr_err("%s: Server Create failed\n", __func__); |
| 1614 | return -ENOMEM; |
| 1615 | } |
| 1616 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1617 | down_read(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1618 | if (!msm_ipc_router_lookup_remote_port( |
| 1619 | msg->srv.node_id, msg->srv.port_id)) { |
| 1620 | rport_ptr = msm_ipc_router_create_remote_port( |
| 1621 | msg->srv.node_id, msg->srv.port_id); |
| 1622 | if (!rport_ptr) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1623 | up_read(&routing_table_lock_lha3); |
| 1624 | up_write(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1625 | return -ENOMEM; |
| 1626 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1627 | rport_ptr->server = server; |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1628 | rport_ptr->sec_rule = msm_ipc_get_security_rule( |
| 1629 | msg->srv.service, |
| 1630 | msg->srv.instance); |
| 1631 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1632 | up_read(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1633 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1634 | up_write(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1635 | |
| 1636 | /* |
| 1637 | * Relay the new server message to other subsystems that do not belong |
| 1638 | * to the cluster from which this message is received. Notify the |
| 1639 | * local clients waiting for this service. |
| 1640 | */ |
| 1641 | relay_msg(xprt_info, pkt); |
| 1642 | post_control_ports(pkt); |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | static int process_rmv_server_msg(struct msm_ipc_router_xprt_info *xprt_info, |
| 1647 | union rr_control_msg *msg, struct rr_packet *pkt) |
| 1648 | { |
| 1649 | struct msm_ipc_server *server; |
| 1650 | |
| 1651 | RR("o REMOVE_SERVER service=%08x:%d\n", |
| 1652 | msg->srv.service, msg->srv.instance); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1653 | down_write(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1654 | server = msm_ipc_router_lookup_server(msg->srv.service, |
| 1655 | msg->srv.instance, msg->srv.node_id, msg->srv.port_id); |
| 1656 | if (server) { |
| 1657 | msm_ipc_router_destroy_server(server, msg->srv.node_id, |
| 1658 | msg->srv.port_id); |
| 1659 | /* |
| 1660 | * Relay the new server message to other subsystems that do not |
| 1661 | * belong to the cluster from which this message is received. |
| 1662 | * Notify the local clients communicating with the service. |
| 1663 | */ |
| 1664 | relay_msg(xprt_info, pkt); |
| 1665 | post_control_ports(pkt); |
| 1666 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1667 | up_write(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1668 | return 0; |
| 1669 | } |
| 1670 | |
| 1671 | static int process_rmv_client_msg(struct msm_ipc_router_xprt_info *xprt_info, |
| 1672 | union rr_control_msg *msg, struct rr_packet *pkt) |
| 1673 | { |
| 1674 | struct msm_ipc_router_remote_port *rport_ptr; |
| 1675 | |
| 1676 | RR("o REMOVE_CLIENT id=%d:%08x\n", msg->cli.node_id, msg->cli.port_id); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1677 | down_write(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1678 | rport_ptr = msm_ipc_router_lookup_remote_port(msg->cli.node_id, |
| 1679 | msg->cli.port_id); |
| 1680 | if (rport_ptr) |
| 1681 | msm_ipc_router_destroy_remote_port(rport_ptr); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1682 | up_write(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1683 | |
| 1684 | relay_msg(xprt_info, pkt); |
| 1685 | post_control_ports(pkt); |
| 1686 | return 0; |
| 1687 | } |
| 1688 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1689 | static int process_control_msg(struct msm_ipc_router_xprt_info *xprt_info, |
| 1690 | struct rr_packet *pkt) |
| 1691 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1692 | union rr_control_msg *msg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1693 | int rc = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1694 | struct sk_buff *temp_ptr; |
| 1695 | struct rr_header *hdr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1696 | |
| 1697 | if (pkt->length != (IPC_ROUTER_HDR_SIZE + sizeof(*msg))) { |
| 1698 | pr_err("%s: r2r msg size %d != %d\n", __func__, pkt->length, |
| 1699 | (IPC_ROUTER_HDR_SIZE + sizeof(*msg))); |
| 1700 | return -EINVAL; |
| 1701 | } |
| 1702 | |
| 1703 | temp_ptr = skb_peek(pkt->pkt_fragment_q); |
Karthikeyan Ramasubramanian | 9024dd8 | 2011-12-19 18:44:19 -0700 | [diff] [blame] | 1704 | if (!temp_ptr) { |
| 1705 | pr_err("%s: pkt_fragment_q is empty\n", __func__); |
| 1706 | return -EINVAL; |
| 1707 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1708 | hdr = (struct rr_header *)temp_ptr->data; |
Karthikeyan Ramasubramanian | 9024dd8 | 2011-12-19 18:44:19 -0700 | [diff] [blame] | 1709 | if (!hdr) { |
| 1710 | pr_err("%s: No data inside the skb\n", __func__); |
| 1711 | return -EINVAL; |
| 1712 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1713 | msg = (union rr_control_msg *)((char *)hdr + IPC_ROUTER_HDR_SIZE); |
| 1714 | |
| 1715 | switch (msg->cmd) { |
| 1716 | case IPC_ROUTER_CTRL_CMD_HELLO: |
Karthikeyan Ramasubramanian | a2b7fdb | 2012-10-23 13:12:44 -0600 | [diff] [blame] | 1717 | rc = process_hello_msg(xprt_info, hdr); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1718 | break; |
| 1719 | case IPC_ROUTER_CTRL_CMD_RESUME_TX: |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1720 | rc = process_resume_tx_msg(msg, pkt); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1721 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1722 | case IPC_ROUTER_CTRL_CMD_NEW_SERVER: |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1723 | rc = process_new_server_msg(xprt_info, msg, pkt); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1724 | break; |
| 1725 | case IPC_ROUTER_CTRL_CMD_REMOVE_SERVER: |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1726 | rc = process_rmv_server_msg(xprt_info, msg, pkt); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1727 | break; |
| 1728 | case IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT: |
Karthikeyan Ramasubramanian | e2e15fa | 2013-05-17 18:18:20 -0600 | [diff] [blame] | 1729 | rc = process_rmv_client_msg(xprt_info, msg, pkt); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1730 | break; |
| 1731 | case IPC_ROUTER_CTRL_CMD_PING: |
| 1732 | /* No action needed for ping messages received */ |
| 1733 | RR("o PING\n"); |
| 1734 | break; |
| 1735 | default: |
| 1736 | RR("o UNKNOWN(%08x)\n", msg->cmd); |
| 1737 | rc = -ENOSYS; |
| 1738 | } |
| 1739 | |
| 1740 | return rc; |
| 1741 | } |
| 1742 | |
| 1743 | static void do_read_data(struct work_struct *work) |
| 1744 | { |
| 1745 | struct rr_header *hdr; |
| 1746 | struct rr_packet *pkt = NULL; |
| 1747 | struct msm_ipc_port *port_ptr; |
| 1748 | struct sk_buff *head_skb; |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1749 | struct msm_ipc_router_remote_port *rport_ptr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1750 | uint32_t resume_tx, resume_tx_node_id, resume_tx_port_id; |
| 1751 | |
| 1752 | struct msm_ipc_router_xprt_info *xprt_info = |
| 1753 | container_of(work, |
| 1754 | struct msm_ipc_router_xprt_info, |
| 1755 | read_data); |
| 1756 | |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1757 | while ((pkt = rr_read(xprt_info)) != NULL) { |
| 1758 | if (pkt->length < IPC_ROUTER_HDR_SIZE || |
| 1759 | pkt->length > MAX_IPC_PKT_SIZE) { |
| 1760 | pr_err("%s: Invalid pkt length %d\n", |
| 1761 | __func__, pkt->length); |
| 1762 | goto fail_data; |
| 1763 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1764 | |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1765 | head_skb = skb_peek(pkt->pkt_fragment_q); |
| 1766 | if (!head_skb) { |
| 1767 | pr_err("%s: head_skb is invalid\n", __func__); |
| 1768 | goto fail_data; |
| 1769 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1770 | |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1771 | hdr = (struct rr_header *)(head_skb->data); |
Karthikeyan Ramasubramanian | 2bfe8ec | 2013-03-22 10:47:20 -0600 | [diff] [blame] | 1772 | RAW("ver=%d type=%d src=%d:%08x crx=%d siz=%d dst=%d:%08x\n", |
| 1773 | hdr->version, hdr->type, hdr->src_node_id, |
| 1774 | hdr->src_port_id, hdr->confirm_rx, hdr->size, |
| 1775 | hdr->dst_node_id, hdr->dst_port_id); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1776 | |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1777 | if (hdr->version != IPC_ROUTER_VERSION) { |
| 1778 | pr_err("version %d != %d\n", |
| 1779 | hdr->version, IPC_ROUTER_VERSION); |
| 1780 | goto fail_data; |
| 1781 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1782 | |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1783 | if ((hdr->dst_node_id != IPC_ROUTER_NID_LOCAL) && |
| 1784 | ((hdr->type == IPC_ROUTER_CTRL_CMD_RESUME_TX) || |
| 1785 | (hdr->type == IPC_ROUTER_CTRL_CMD_DATA))) { |
| 1786 | forward_msg(xprt_info, pkt); |
| 1787 | release_pkt(pkt); |
| 1788 | continue; |
| 1789 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1790 | |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1791 | if ((hdr->dst_port_id == IPC_ROUTER_ADDRESS) || |
| 1792 | (hdr->type == IPC_ROUTER_CTRL_CMD_HELLO)) { |
| 1793 | process_control_msg(xprt_info, pkt); |
| 1794 | release_pkt(pkt); |
| 1795 | continue; |
| 1796 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1797 | #if defined(CONFIG_MSM_SMD_LOGGING) |
| 1798 | #if defined(DEBUG) |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1799 | if (msm_ipc_router_debug_mask & SMEM_LOG) { |
| 1800 | smem_log_event((SMEM_LOG_PROC_ID_APPS | |
| 1801 | SMEM_LOG_RPC_ROUTER_EVENT_BASE | |
| 1802 | IPC_ROUTER_LOG_EVENT_RX), |
| 1803 | (hdr->src_node_id << 24) | |
| 1804 | (hdr->src_port_id & 0xffffff), |
| 1805 | (hdr->dst_node_id << 24) | |
| 1806 | (hdr->dst_port_id & 0xffffff), |
| 1807 | (hdr->type << 24) | (hdr->confirm_rx << 16) | |
| 1808 | (hdr->size & 0xffff)); |
| 1809 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1810 | #endif |
| 1811 | #endif |
| 1812 | |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1813 | resume_tx = hdr->confirm_rx; |
| 1814 | resume_tx_node_id = hdr->dst_node_id; |
| 1815 | resume_tx_port_id = hdr->dst_port_id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1816 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1817 | down_read(&local_ports_lock_lha2); |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1818 | port_ptr = msm_ipc_router_lookup_local_port(hdr->dst_port_id); |
| 1819 | if (!port_ptr) { |
| 1820 | pr_err("%s: No local port id %08x\n", __func__, |
| 1821 | hdr->dst_port_id); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1822 | up_read(&local_ports_lock_lha2); |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1823 | release_pkt(pkt); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1824 | goto process_done; |
| 1825 | } |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1826 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1827 | down_read(&routing_table_lock_lha3); |
| 1828 | rport_ptr = msm_ipc_router_lookup_remote_port(hdr->src_node_id, |
| 1829 | hdr->src_port_id); |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1830 | if (!rport_ptr) { |
| 1831 | rport_ptr = msm_ipc_router_create_remote_port( |
| 1832 | hdr->src_node_id, |
| 1833 | hdr->src_port_id); |
| 1834 | if (!rport_ptr) { |
| 1835 | pr_err("%s: Rmt Prt %08x:%08x create failed\n", |
| 1836 | __func__, hdr->src_node_id, |
| 1837 | hdr->src_port_id); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1838 | up_read(&routing_table_lock_lha3); |
| 1839 | up_read(&local_ports_lock_lha2); |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1840 | goto process_done; |
| 1841 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1842 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1843 | up_read(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | 6dbb00f | 2013-05-17 15:19:56 -0600 | [diff] [blame] | 1844 | post_pkt_to_port(port_ptr, pkt, 0); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1845 | up_read(&local_ports_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1846 | |
| 1847 | process_done: |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1848 | if (resume_tx) { |
| 1849 | union rr_control_msg msg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1850 | |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1851 | msg.cmd = IPC_ROUTER_CTRL_CMD_RESUME_TX; |
| 1852 | msg.cli.node_id = resume_tx_node_id; |
| 1853 | msg.cli.port_id = resume_tx_port_id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1854 | |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 1855 | RR("x RESUME_TX id=%d:%08x\n", |
| 1856 | msg.cli.node_id, msg.cli.port_id); |
| 1857 | msm_ipc_router_send_control_msg(xprt_info, &msg); |
| 1858 | } |
| 1859 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1860 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1861 | return; |
| 1862 | |
| 1863 | fail_data: |
| 1864 | release_pkt(pkt); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1865 | pr_err("ipc_router has died\n"); |
| 1866 | } |
| 1867 | |
| 1868 | int msm_ipc_router_register_server(struct msm_ipc_port *port_ptr, |
| 1869 | struct msm_ipc_addr *name) |
| 1870 | { |
| 1871 | struct msm_ipc_server *server; |
| 1872 | unsigned long flags; |
| 1873 | union rr_control_msg ctl; |
| 1874 | |
| 1875 | if (!port_ptr || !name) |
| 1876 | return -EINVAL; |
| 1877 | |
| 1878 | if (name->addrtype != MSM_IPC_ADDR_NAME) |
| 1879 | return -EINVAL; |
| 1880 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1881 | down_write(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1882 | server = msm_ipc_router_lookup_server(name->addr.port_name.service, |
| 1883 | name->addr.port_name.instance, |
| 1884 | IPC_ROUTER_NID_LOCAL, |
| 1885 | port_ptr->this_port.port_id); |
| 1886 | if (server) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1887 | up_write(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1888 | pr_err("%s: Server already present\n", __func__); |
| 1889 | return -EINVAL; |
| 1890 | } |
| 1891 | |
| 1892 | server = msm_ipc_router_create_server(name->addr.port_name.service, |
| 1893 | name->addr.port_name.instance, |
| 1894 | IPC_ROUTER_NID_LOCAL, |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 1895 | port_ptr->this_port.port_id, |
| 1896 | NULL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1897 | if (!server) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1898 | up_write(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1899 | pr_err("%s: Server Creation failed\n", __func__); |
| 1900 | return -EINVAL; |
| 1901 | } |
| 1902 | |
| 1903 | ctl.cmd = IPC_ROUTER_CTRL_CMD_NEW_SERVER; |
| 1904 | ctl.srv.service = server->name.service; |
| 1905 | ctl.srv.instance = server->name.instance; |
| 1906 | ctl.srv.node_id = IPC_ROUTER_NID_LOCAL; |
| 1907 | ctl.srv.port_id = port_ptr->this_port.port_id; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1908 | up_write(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1909 | broadcast_ctl_msg(&ctl); |
| 1910 | spin_lock_irqsave(&port_ptr->port_lock, flags); |
| 1911 | port_ptr->type = SERVER_PORT; |
Karthikeyan Ramasubramanian | 96cced7 | 2013-05-02 17:25:54 -0600 | [diff] [blame] | 1912 | port_ptr->mode_info.mode = MULTI_LINK_MODE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1913 | port_ptr->port_name.service = server->name.service; |
| 1914 | port_ptr->port_name.instance = server->name.instance; |
| 1915 | spin_unlock_irqrestore(&port_ptr->port_lock, flags); |
| 1916 | return 0; |
| 1917 | } |
| 1918 | |
| 1919 | int msm_ipc_router_unregister_server(struct msm_ipc_port *port_ptr) |
| 1920 | { |
| 1921 | struct msm_ipc_server *server; |
| 1922 | unsigned long flags; |
| 1923 | union rr_control_msg ctl; |
| 1924 | |
| 1925 | if (!port_ptr) |
| 1926 | return -EINVAL; |
| 1927 | |
| 1928 | if (port_ptr->type != SERVER_PORT) { |
| 1929 | pr_err("%s: Trying to unregister a non-server port\n", |
| 1930 | __func__); |
| 1931 | return -EINVAL; |
| 1932 | } |
| 1933 | |
| 1934 | if (port_ptr->this_port.node_id != IPC_ROUTER_NID_LOCAL) { |
| 1935 | pr_err("%s: Trying to unregister a remote server locally\n", |
| 1936 | __func__); |
| 1937 | return -EINVAL; |
| 1938 | } |
| 1939 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1940 | down_write(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1941 | server = msm_ipc_router_lookup_server(port_ptr->port_name.service, |
| 1942 | port_ptr->port_name.instance, |
| 1943 | port_ptr->this_port.node_id, |
| 1944 | port_ptr->this_port.port_id); |
| 1945 | if (!server) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1946 | up_write(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1947 | pr_err("%s: Server lookup failed\n", __func__); |
| 1948 | return -ENODEV; |
| 1949 | } |
| 1950 | |
| 1951 | ctl.cmd = IPC_ROUTER_CTRL_CMD_REMOVE_SERVER; |
| 1952 | ctl.srv.service = server->name.service; |
| 1953 | ctl.srv.instance = server->name.instance; |
| 1954 | ctl.srv.node_id = IPC_ROUTER_NID_LOCAL; |
| 1955 | ctl.srv.port_id = port_ptr->this_port.port_id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1956 | msm_ipc_router_destroy_server(server, port_ptr->this_port.node_id, |
| 1957 | port_ptr->this_port.port_id); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 1958 | up_write(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 1959 | broadcast_ctl_msg(&ctl); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1960 | spin_lock_irqsave(&port_ptr->port_lock, flags); |
| 1961 | port_ptr->type = CLIENT_PORT; |
| 1962 | spin_unlock_irqrestore(&port_ptr->port_lock, flags); |
| 1963 | return 0; |
| 1964 | } |
| 1965 | |
| 1966 | static int loopback_data(struct msm_ipc_port *src, |
| 1967 | uint32_t port_id, |
| 1968 | struct sk_buff_head *data) |
| 1969 | { |
| 1970 | struct sk_buff *head_skb; |
| 1971 | struct rr_header *hdr; |
| 1972 | struct msm_ipc_port *port_ptr; |
| 1973 | struct rr_packet *pkt; |
Karthikeyan Ramasubramanian | b0e23c5 | 2013-02-08 13:07:42 -0700 | [diff] [blame] | 1974 | int ret_len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1975 | |
| 1976 | if (!data) { |
| 1977 | pr_err("%s: Invalid pkt pointer\n", __func__); |
| 1978 | return -EINVAL; |
| 1979 | } |
| 1980 | |
| 1981 | pkt = create_pkt(data); |
| 1982 | if (!pkt) { |
| 1983 | pr_err("%s: New pkt create failed\n", __func__); |
| 1984 | return -ENOMEM; |
| 1985 | } |
| 1986 | |
| 1987 | head_skb = skb_peek(pkt->pkt_fragment_q); |
Karthikeyan Ramasubramanian | 9024dd8 | 2011-12-19 18:44:19 -0700 | [diff] [blame] | 1988 | if (!head_skb) { |
| 1989 | pr_err("%s: pkt_fragment_q is empty\n", __func__); |
Brent Hronik | 1c9a3d4 | 2013-04-17 15:10:40 -0600 | [diff] [blame] | 1990 | release_pkt(pkt); |
Karthikeyan Ramasubramanian | 9024dd8 | 2011-12-19 18:44:19 -0700 | [diff] [blame] | 1991 | return -EINVAL; |
| 1992 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1993 | hdr = (struct rr_header *)skb_push(head_skb, IPC_ROUTER_HDR_SIZE); |
| 1994 | if (!hdr) { |
| 1995 | pr_err("%s: Prepend Header failed\n", __func__); |
| 1996 | release_pkt(pkt); |
| 1997 | return -ENOMEM; |
| 1998 | } |
| 1999 | hdr->version = IPC_ROUTER_VERSION; |
| 2000 | hdr->type = IPC_ROUTER_CTRL_CMD_DATA; |
| 2001 | hdr->src_node_id = src->this_port.node_id; |
| 2002 | hdr->src_port_id = src->this_port.port_id; |
| 2003 | hdr->size = pkt->length; |
| 2004 | hdr->confirm_rx = 0; |
| 2005 | hdr->dst_node_id = IPC_ROUTER_NID_LOCAL; |
| 2006 | hdr->dst_port_id = port_id; |
| 2007 | pkt->length += IPC_ROUTER_HDR_SIZE; |
| 2008 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2009 | down_read(&local_ports_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2010 | port_ptr = msm_ipc_router_lookup_local_port(port_id); |
| 2011 | if (!port_ptr) { |
| 2012 | pr_err("%s: Local port %d not present\n", __func__, port_id); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2013 | up_read(&local_ports_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2014 | release_pkt(pkt); |
| 2015 | return -ENODEV; |
| 2016 | } |
| 2017 | |
Karthikeyan Ramasubramanian | b0e23c5 | 2013-02-08 13:07:42 -0700 | [diff] [blame] | 2018 | ret_len = pkt->length; |
Karthikeyan Ramasubramanian | 6dbb00f | 2013-05-17 15:19:56 -0600 | [diff] [blame] | 2019 | post_pkt_to_port(port_ptr, pkt, 0); |
Karthikeyan Ramasubramanian | 96cced7 | 2013-05-02 17:25:54 -0600 | [diff] [blame] | 2020 | update_comm_mode_info(&src->mode_info, NULL); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2021 | up_read(&local_ports_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2022 | |
Karthikeyan Ramasubramanian | b0e23c5 | 2013-02-08 13:07:42 -0700 | [diff] [blame] | 2023 | return ret_len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | static int msm_ipc_router_write_pkt(struct msm_ipc_port *src, |
| 2027 | struct msm_ipc_router_remote_port *rport_ptr, |
| 2028 | struct rr_packet *pkt) |
| 2029 | { |
| 2030 | struct sk_buff *head_skb; |
| 2031 | struct rr_header *hdr; |
| 2032 | struct msm_ipc_router_xprt_info *xprt_info; |
| 2033 | struct msm_ipc_routing_table_entry *rt_entry; |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 2034 | struct msm_ipc_resume_tx_port *resume_tx_port; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2035 | int ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2036 | |
| 2037 | if (!rport_ptr || !src || !pkt) |
| 2038 | return -EINVAL; |
| 2039 | |
| 2040 | head_skb = skb_peek(pkt->pkt_fragment_q); |
Karthikeyan Ramasubramanian | 9024dd8 | 2011-12-19 18:44:19 -0700 | [diff] [blame] | 2041 | if (!head_skb) { |
| 2042 | pr_err("%s: pkt_fragment_q is empty\n", __func__); |
| 2043 | return -EINVAL; |
| 2044 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2045 | hdr = (struct rr_header *)skb_push(head_skb, IPC_ROUTER_HDR_SIZE); |
| 2046 | if (!hdr) { |
| 2047 | pr_err("%s: Prepend Header failed\n", __func__); |
| 2048 | return -ENOMEM; |
| 2049 | } |
| 2050 | hdr->version = IPC_ROUTER_VERSION; |
| 2051 | hdr->type = IPC_ROUTER_CTRL_CMD_DATA; |
| 2052 | hdr->src_node_id = src->this_port.node_id; |
| 2053 | hdr->src_port_id = src->this_port.port_id; |
| 2054 | hdr->size = pkt->length; |
| 2055 | hdr->confirm_rx = 0; |
| 2056 | hdr->dst_node_id = rport_ptr->node_id; |
| 2057 | hdr->dst_port_id = rport_ptr->port_id; |
| 2058 | pkt->length += IPC_ROUTER_HDR_SIZE; |
| 2059 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2060 | mutex_lock(&rport_ptr->quota_lock_lhb2); |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 2061 | if (rport_ptr->tx_quota_cnt == IPC_ROUTER_DEFAULT_RX_QUOTA) { |
| 2062 | if (msm_ipc_router_lookup_resume_tx_port( |
| 2063 | rport_ptr, src->this_port.port_id)) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2064 | mutex_unlock(&rport_ptr->quota_lock_lhb2); |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 2065 | return -EAGAIN; |
| 2066 | } |
| 2067 | resume_tx_port = |
| 2068 | kzalloc(sizeof(struct msm_ipc_resume_tx_port), |
| 2069 | GFP_KERNEL); |
| 2070 | if (!resume_tx_port) { |
| 2071 | pr_err("%s: Resume_Tx port allocation failed\n", |
| 2072 | __func__); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2073 | mutex_unlock(&rport_ptr->quota_lock_lhb2); |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 2074 | return -ENOMEM; |
| 2075 | } |
| 2076 | INIT_LIST_HEAD(&resume_tx_port->list); |
| 2077 | resume_tx_port->port_id = src->this_port.port_id; |
| 2078 | resume_tx_port->node_id = src->this_port.node_id; |
| 2079 | list_add_tail(&resume_tx_port->list, |
| 2080 | &rport_ptr->resume_tx_port_list); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2081 | mutex_unlock(&rport_ptr->quota_lock_lhb2); |
Zaheerulla Meer | e3f6c3a | 2013-04-17 01:16:47 +0530 | [diff] [blame] | 2082 | return -EAGAIN; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2083 | } |
| 2084 | rport_ptr->tx_quota_cnt++; |
| 2085 | if (rport_ptr->tx_quota_cnt == IPC_ROUTER_DEFAULT_RX_QUOTA) |
| 2086 | hdr->confirm_rx = 1; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2087 | mutex_unlock(&rport_ptr->quota_lock_lhb2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2088 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2089 | rt_entry = lookup_routing_table(hdr->dst_node_id); |
| 2090 | if (!rt_entry || !rt_entry->xprt_info) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2091 | pr_err("%s: Remote node %d not up\n", |
| 2092 | __func__, hdr->dst_node_id); |
| 2093 | return -ENODEV; |
| 2094 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2095 | down_read(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2096 | xprt_info = rt_entry->xprt_info; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2097 | mutex_lock(&xprt_info->tx_lock_lhb2); |
Karthikeyan Ramasubramanian | 8cec592 | 2012-02-16 17:41:58 -0700 | [diff] [blame] | 2098 | ret = xprt_info->xprt->write(pkt, pkt->length, xprt_info->xprt); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2099 | mutex_unlock(&xprt_info->tx_lock_lhb2); |
| 2100 | up_read(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2101 | |
| 2102 | if (ret < 0) { |
| 2103 | pr_err("%s: Write on XPRT failed\n", __func__); |
| 2104 | return ret; |
| 2105 | } |
Karthikeyan Ramasubramanian | 96cced7 | 2013-05-02 17:25:54 -0600 | [diff] [blame] | 2106 | update_comm_mode_info(&src->mode_info, xprt_info); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2107 | |
| 2108 | RAW_HDR("[w rr_h] " |
| 2109 | "ver=%i,type=%s,src_nid=%08x,src_port_id=%08x," |
| 2110 | "confirm_rx=%i,size=%3i,dst_pid=%08x,dst_cid=%08x\n", |
| 2111 | hdr->version, type_to_str(hdr->type), |
| 2112 | hdr->src_node_id, hdr->src_port_id, |
| 2113 | hdr->confirm_rx, hdr->size, |
| 2114 | hdr->dst_node_id, hdr->dst_port_id); |
| 2115 | |
| 2116 | #if defined(CONFIG_MSM_SMD_LOGGING) |
| 2117 | #if defined(DEBUG) |
| 2118 | if (msm_ipc_router_debug_mask & SMEM_LOG) { |
| 2119 | smem_log_event((SMEM_LOG_PROC_ID_APPS | |
| 2120 | SMEM_LOG_RPC_ROUTER_EVENT_BASE | |
| 2121 | IPC_ROUTER_LOG_EVENT_TX), |
| 2122 | (hdr->src_node_id << 24) | |
| 2123 | (hdr->src_port_id & 0xffffff), |
| 2124 | (hdr->dst_node_id << 24) | |
| 2125 | (hdr->dst_port_id & 0xffffff), |
| 2126 | (hdr->type << 24) | (hdr->confirm_rx << 16) | |
| 2127 | (hdr->size & 0xffff)); |
| 2128 | } |
| 2129 | #endif |
| 2130 | #endif |
| 2131 | |
| 2132 | return pkt->length; |
| 2133 | } |
| 2134 | |
| 2135 | int msm_ipc_router_send_to(struct msm_ipc_port *src, |
| 2136 | struct sk_buff_head *data, |
| 2137 | struct msm_ipc_addr *dest) |
| 2138 | { |
| 2139 | uint32_t dst_node_id = 0, dst_port_id = 0; |
| 2140 | struct msm_ipc_server *server; |
| 2141 | struct msm_ipc_server_port *server_port; |
| 2142 | struct msm_ipc_router_remote_port *rport_ptr = NULL; |
| 2143 | struct rr_packet *pkt; |
| 2144 | int ret; |
| 2145 | |
| 2146 | if (!src || !data || !dest) { |
| 2147 | pr_err("%s: Invalid Parameters\n", __func__); |
| 2148 | return -EINVAL; |
| 2149 | } |
| 2150 | |
| 2151 | /* Resolve Address*/ |
| 2152 | if (dest->addrtype == MSM_IPC_ADDR_ID) { |
| 2153 | dst_node_id = dest->addr.port_addr.node_id; |
| 2154 | dst_port_id = dest->addr.port_addr.port_id; |
| 2155 | } else if (dest->addrtype == MSM_IPC_ADDR_NAME) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2156 | down_read(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2157 | server = msm_ipc_router_lookup_server( |
| 2158 | dest->addr.port_name.service, |
| 2159 | dest->addr.port_name.instance, |
| 2160 | 0, 0); |
| 2161 | if (!server) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2162 | up_read(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2163 | pr_err("%s: Destination not reachable\n", __func__); |
| 2164 | return -ENODEV; |
| 2165 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2166 | server_port = list_first_entry(&server->server_port_list, |
| 2167 | struct msm_ipc_server_port, |
| 2168 | list); |
| 2169 | dst_node_id = server_port->server_addr.node_id; |
| 2170 | dst_port_id = server_port->server_addr.port_id; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2171 | up_read(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2172 | } |
| 2173 | if (dst_node_id == IPC_ROUTER_NID_LOCAL) { |
| 2174 | ret = loopback_data(src, dst_port_id, data); |
| 2175 | return ret; |
| 2176 | } |
| 2177 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2178 | down_read(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2179 | rport_ptr = msm_ipc_router_lookup_remote_port(dst_node_id, |
| 2180 | dst_port_id); |
| 2181 | if (!rport_ptr) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2182 | up_read(&routing_table_lock_lha3); |
Zaheerulla Meer | 3d8b0a0 | 2013-05-10 15:51:28 +0530 | [diff] [blame] | 2183 | pr_err("%s: Remote port not found\n", __func__); |
| 2184 | return -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 2187 | if (src->check_send_permissions) { |
| 2188 | ret = src->check_send_permissions(rport_ptr->sec_rule); |
| 2189 | if (ret <= 0) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2190 | up_read(&routing_table_lock_lha3); |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 2191 | pr_err("%s: permission failure for %s\n", |
| 2192 | __func__, current->comm); |
| 2193 | return -EPERM; |
| 2194 | } |
| 2195 | } |
| 2196 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2197 | pkt = create_pkt(data); |
| 2198 | if (!pkt) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2199 | up_read(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2200 | pr_err("%s: Pkt creation failed\n", __func__); |
| 2201 | return -ENOMEM; |
| 2202 | } |
| 2203 | |
| 2204 | ret = msm_ipc_router_write_pkt(src, rport_ptr, pkt); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2205 | up_read(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2206 | release_pkt(pkt); |
| 2207 | |
| 2208 | return ret; |
| 2209 | } |
| 2210 | |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 2211 | int msm_ipc_router_send_msg(struct msm_ipc_port *src, |
| 2212 | struct msm_ipc_addr *dest, |
| 2213 | void *data, unsigned int data_len) |
| 2214 | { |
| 2215 | struct sk_buff_head *out_skb_head; |
| 2216 | int ret; |
| 2217 | |
| 2218 | out_skb_head = msm_ipc_router_buf_to_skb(data, data_len); |
| 2219 | if (!out_skb_head) { |
| 2220 | pr_err("%s: SKB conversion failed\n", __func__); |
| 2221 | return -EFAULT; |
| 2222 | } |
| 2223 | |
| 2224 | ret = msm_ipc_router_send_to(src, out_skb_head, dest); |
Zaheerulla Meer | 51dc3a1 | 2013-05-08 19:27:27 +0530 | [diff] [blame] | 2225 | if (ret == -EAGAIN) |
| 2226 | return ret; |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 2227 | if (ret < 0) { |
| 2228 | pr_err("%s: msm_ipc_router_send_to failed - ret: %d\n", |
| 2229 | __func__, ret); |
| 2230 | msm_ipc_router_free_skb(out_skb_head); |
Zaheerulla Meer | 2f1eb07 | 2013-06-26 22:39:00 +0530 | [diff] [blame] | 2231 | return ret; |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 2232 | } |
| 2233 | return 0; |
| 2234 | } |
| 2235 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2236 | int msm_ipc_router_read(struct msm_ipc_port *port_ptr, |
| 2237 | struct sk_buff_head **data, |
| 2238 | size_t buf_len) |
| 2239 | { |
| 2240 | struct rr_packet *pkt; |
| 2241 | int ret; |
| 2242 | |
| 2243 | if (!port_ptr || !data) |
| 2244 | return -EINVAL; |
| 2245 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2246 | mutex_lock(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2247 | if (list_empty(&port_ptr->port_rx_q)) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2248 | mutex_unlock(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2249 | return -EAGAIN; |
| 2250 | } |
| 2251 | |
| 2252 | pkt = list_first_entry(&port_ptr->port_rx_q, struct rr_packet, list); |
| 2253 | if ((buf_len) && ((pkt->length - IPC_ROUTER_HDR_SIZE) > buf_len)) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2254 | mutex_unlock(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2255 | return -ETOOSMALL; |
| 2256 | } |
| 2257 | list_del(&pkt->list); |
| 2258 | if (list_empty(&port_ptr->port_rx_q)) |
| 2259 | wake_unlock(&port_ptr->port_rx_wake_lock); |
| 2260 | *data = pkt->pkt_fragment_q; |
| 2261 | ret = pkt->length; |
| 2262 | kfree(pkt); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2263 | mutex_unlock(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2264 | |
| 2265 | return ret; |
| 2266 | } |
| 2267 | |
Zaheerulla Meer | abb0eba | 2013-05-22 23:31:59 +0530 | [diff] [blame] | 2268 | /** |
| 2269 | * msm_ipc_router_recv_from() - Recieve messages destined to a local port. |
| 2270 | * @port_ptr: Pointer to the local port |
| 2271 | * @data : Pointer to the socket buffer head |
| 2272 | * @src: Pointer to local port address |
| 2273 | * @timeout: < 0 timeout indicates infinite wait till a message arrives. |
| 2274 | * > 0 timeout indicates the wait time. |
| 2275 | * 0 indicates that we do not wait. |
| 2276 | * @return: = Number of bytes read(On successful read operation). |
| 2277 | * = 0 (If there are no pending messages and timeout is 0). |
| 2278 | * = -EINVAL (If either of the arguments, port_ptr or data is invalid) |
| 2279 | * = -EFAULT (If there are no pending messages when timeout is > 0 |
| 2280 | * and the wait_event_interruptible_timeout has returned value > 0) |
| 2281 | * = -ERESTARTSYS (If there are no pending messages when timeout |
| 2282 | * is < 0 and wait_event_interruptible was interrupted by a signal) |
| 2283 | * |
| 2284 | * This function reads the messages that are destined for a local port. It |
| 2285 | * is used by modules that exist with-in the kernel and use IPC Router for |
| 2286 | * transport. The function checks if there are any messages that are already |
| 2287 | * received. If yes, it reads them, else it waits as per the timeout value. |
| 2288 | * On a successful read, the return value of the function indicates the number |
| 2289 | * of bytes that are read. |
| 2290 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2291 | int msm_ipc_router_recv_from(struct msm_ipc_port *port_ptr, |
| 2292 | struct sk_buff_head **data, |
| 2293 | struct msm_ipc_addr *src, |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 2294 | long timeout) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2295 | { |
| 2296 | int ret, data_len, align_size; |
| 2297 | struct sk_buff *temp_skb; |
| 2298 | struct rr_header *hdr = NULL; |
| 2299 | |
| 2300 | if (!port_ptr || !data) { |
| 2301 | pr_err("%s: Invalid pointers being passed\n", __func__); |
| 2302 | return -EINVAL; |
| 2303 | } |
| 2304 | |
| 2305 | *data = NULL; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2306 | mutex_lock(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2307 | while (list_empty(&port_ptr->port_rx_q)) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2308 | mutex_unlock(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2309 | if (timeout < 0) { |
| 2310 | ret = wait_event_interruptible( |
| 2311 | port_ptr->port_rx_wait_q, |
| 2312 | !list_empty(&port_ptr->port_rx_q)); |
| 2313 | if (ret) |
| 2314 | return ret; |
| 2315 | } else if (timeout > 0) { |
| 2316 | timeout = wait_event_interruptible_timeout( |
| 2317 | port_ptr->port_rx_wait_q, |
| 2318 | !list_empty(&port_ptr->port_rx_q), |
| 2319 | timeout); |
| 2320 | if (timeout < 0) |
| 2321 | return -EFAULT; |
| 2322 | } |
| 2323 | if (timeout == 0) |
Zaheerulla Meer | abb0eba | 2013-05-22 23:31:59 +0530 | [diff] [blame] | 2324 | return 0; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2325 | mutex_lock(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2326 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2327 | mutex_unlock(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2328 | |
| 2329 | ret = msm_ipc_router_read(port_ptr, data, 0); |
| 2330 | if (ret <= 0 || !(*data)) |
| 2331 | return ret; |
| 2332 | |
| 2333 | temp_skb = skb_peek(*data); |
| 2334 | hdr = (struct rr_header *)(temp_skb->data); |
| 2335 | if (src) { |
| 2336 | src->addrtype = MSM_IPC_ADDR_ID; |
| 2337 | src->addr.port_addr.node_id = hdr->src_node_id; |
| 2338 | src->addr.port_addr.port_id = hdr->src_port_id; |
| 2339 | } |
| 2340 | |
| 2341 | data_len = hdr->size; |
| 2342 | skb_pull(temp_skb, IPC_ROUTER_HDR_SIZE); |
| 2343 | align_size = ALIGN_SIZE(data_len); |
| 2344 | if (align_size) { |
| 2345 | temp_skb = skb_peek_tail(*data); |
| 2346 | skb_trim(temp_skb, (temp_skb->len - align_size)); |
| 2347 | } |
| 2348 | return data_len; |
| 2349 | } |
| 2350 | |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 2351 | int msm_ipc_router_read_msg(struct msm_ipc_port *port_ptr, |
| 2352 | struct msm_ipc_addr *src, |
| 2353 | unsigned char **data, |
| 2354 | unsigned int *len) |
| 2355 | { |
| 2356 | struct sk_buff_head *in_skb_head; |
| 2357 | int ret; |
| 2358 | |
Zaheerulla Meer | abb0eba | 2013-05-22 23:31:59 +0530 | [diff] [blame] | 2359 | ret = msm_ipc_router_recv_from(port_ptr, &in_skb_head, src, 0); |
| 2360 | |
| 2361 | if (ret == 0) |
| 2362 | return -ENOMSG; |
| 2363 | |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 2364 | if (ret < 0) { |
| 2365 | pr_err("%s: msm_ipc_router_recv_from failed - ret: %d\n", |
| 2366 | __func__, ret); |
| 2367 | return ret; |
| 2368 | } |
| 2369 | |
| 2370 | *data = msm_ipc_router_skb_to_buf(in_skb_head, ret); |
| 2371 | if (!(*data)) |
| 2372 | pr_err("%s: Buf conversion failed\n", __func__); |
| 2373 | |
| 2374 | *len = ret; |
| 2375 | msm_ipc_router_free_skb(in_skb_head); |
| 2376 | return 0; |
| 2377 | } |
| 2378 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2379 | struct msm_ipc_port *msm_ipc_router_create_port( |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 2380 | void (*notify)(unsigned event, void *priv), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2381 | void *priv) |
| 2382 | { |
| 2383 | struct msm_ipc_port *port_ptr; |
Karthikeyan Ramasubramanian | efc493b | 2012-07-12 10:25:49 -0600 | [diff] [blame] | 2384 | int ret; |
| 2385 | |
| 2386 | ret = wait_for_completion_interruptible(&msm_ipc_local_router_up); |
| 2387 | if (ret < 0) { |
| 2388 | pr_err("%s: Error waiting for local router\n", __func__); |
| 2389 | return NULL; |
| 2390 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2391 | |
| 2392 | port_ptr = msm_ipc_router_create_raw_port(NULL, notify, priv); |
| 2393 | if (!port_ptr) |
| 2394 | pr_err("%s: port_ptr alloc failed\n", __func__); |
| 2395 | |
| 2396 | return port_ptr; |
| 2397 | } |
| 2398 | |
| 2399 | int msm_ipc_router_close_port(struct msm_ipc_port *port_ptr) |
| 2400 | { |
| 2401 | union rr_control_msg msg; |
| 2402 | struct rr_packet *pkt, *temp_pkt; |
| 2403 | struct msm_ipc_server *server; |
| 2404 | |
| 2405 | if (!port_ptr) |
| 2406 | return -EINVAL; |
| 2407 | |
| 2408 | if (port_ptr->type == SERVER_PORT || port_ptr->type == CLIENT_PORT) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2409 | down_write(&local_ports_lock_lha2); |
Karthikeyan Ramasubramanian | be9954b | 2012-06-13 12:59:54 -0600 | [diff] [blame] | 2410 | list_del(&port_ptr->list); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2411 | up_write(&local_ports_lock_lha2); |
Karthikeyan Ramasubramanian | be9954b | 2012-06-13 12:59:54 -0600 | [diff] [blame] | 2412 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2413 | if (port_ptr->type == SERVER_PORT) { |
| 2414 | msg.cmd = IPC_ROUTER_CTRL_CMD_REMOVE_SERVER; |
| 2415 | msg.srv.service = port_ptr->port_name.service; |
| 2416 | msg.srv.instance = port_ptr->port_name.instance; |
| 2417 | msg.srv.node_id = port_ptr->this_port.node_id; |
| 2418 | msg.srv.port_id = port_ptr->this_port.port_id; |
| 2419 | RR("x REMOVE_SERVER Name=%d:%08x Id=%d:%08x\n", |
| 2420 | msg.srv.service, msg.srv.instance, |
| 2421 | msg.srv.node_id, msg.srv.port_id); |
Karthikeyan Ramasubramanian | 5c568fb | 2013-01-10 17:09:13 -0700 | [diff] [blame] | 2422 | broadcast_ctl_msg(&msg); |
| 2423 | broadcast_ctl_msg_locally(&msg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2424 | } |
Karthikeyan Ramasubramanian | 5c568fb | 2013-01-10 17:09:13 -0700 | [diff] [blame] | 2425 | |
| 2426 | /* |
| 2427 | * Server port could have been a client port earlier. |
| 2428 | * Send REMOVE_CLIENT message in either case. |
| 2429 | */ |
Karthikeyan Ramasubramanian | 5c568fb | 2013-01-10 17:09:13 -0700 | [diff] [blame] | 2430 | RR("x REMOVE_CLIENT id=%d:%08x\n", |
Karthikeyan Ramasubramanian | 96cced7 | 2013-05-02 17:25:54 -0600 | [diff] [blame] | 2431 | port_ptr->this_port.node_id, port_ptr->this_port.port_id); |
| 2432 | msm_ipc_router_send_remove_client(&port_ptr->mode_info, |
| 2433 | port_ptr->this_port.node_id, |
| 2434 | port_ptr->this_port.port_id); |
Karthikeyan Ramasubramanian | be9954b | 2012-06-13 12:59:54 -0600 | [diff] [blame] | 2435 | } else if (port_ptr->type == CONTROL_PORT) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2436 | down_write(&control_ports_lock_lha5); |
Karthikeyan Ramasubramanian | be9954b | 2012-06-13 12:59:54 -0600 | [diff] [blame] | 2437 | list_del(&port_ptr->list); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2438 | up_write(&control_ports_lock_lha5); |
Karthikeyan Ramasubramanian | f7a4b6e | 2013-01-16 09:00:28 -0700 | [diff] [blame] | 2439 | } else if (port_ptr->type == IRSC_PORT) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2440 | down_write(&local_ports_lock_lha2); |
Karthikeyan Ramasubramanian | f7a4b6e | 2013-01-16 09:00:28 -0700 | [diff] [blame] | 2441 | list_del(&port_ptr->list); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2442 | up_write(&local_ports_lock_lha2); |
Karthikeyan Ramasubramanian | f7a4b6e | 2013-01-16 09:00:28 -0700 | [diff] [blame] | 2443 | signal_irsc_completion(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2444 | } |
| 2445 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2446 | mutex_lock(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2447 | list_for_each_entry_safe(pkt, temp_pkt, &port_ptr->port_rx_q, list) { |
| 2448 | list_del(&pkt->list); |
| 2449 | release_pkt(pkt); |
| 2450 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2451 | mutex_unlock(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2452 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2453 | if (port_ptr->type == SERVER_PORT) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2454 | down_write(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2455 | server = msm_ipc_router_lookup_server( |
| 2456 | port_ptr->port_name.service, |
| 2457 | port_ptr->port_name.instance, |
| 2458 | port_ptr->this_port.node_id, |
| 2459 | port_ptr->this_port.port_id); |
| 2460 | if (server) |
| 2461 | msm_ipc_router_destroy_server(server, |
| 2462 | port_ptr->this_port.node_id, |
| 2463 | port_ptr->this_port.port_id); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2464 | up_write(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
Karthikeyan Ramasubramanian | dd8c3b5 | 2011-11-30 16:26:12 -0700 | [diff] [blame] | 2467 | wake_lock_destroy(&port_ptr->port_rx_wake_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2468 | kfree(port_ptr); |
| 2469 | return 0; |
| 2470 | } |
| 2471 | |
| 2472 | int msm_ipc_router_get_curr_pkt_size(struct msm_ipc_port *port_ptr) |
| 2473 | { |
| 2474 | struct rr_packet *pkt; |
| 2475 | int rc = 0; |
| 2476 | |
| 2477 | if (!port_ptr) |
| 2478 | return -EINVAL; |
| 2479 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2480 | mutex_lock(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2481 | if (!list_empty(&port_ptr->port_rx_q)) { |
| 2482 | pkt = list_first_entry(&port_ptr->port_rx_q, |
| 2483 | struct rr_packet, list); |
| 2484 | rc = pkt->length; |
| 2485 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2486 | mutex_unlock(&port_ptr->port_rx_q_lock_lhb3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2487 | |
| 2488 | return rc; |
| 2489 | } |
| 2490 | |
| 2491 | int msm_ipc_router_bind_control_port(struct msm_ipc_port *port_ptr) |
| 2492 | { |
| 2493 | if (!port_ptr) |
| 2494 | return -EINVAL; |
| 2495 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2496 | down_write(&local_ports_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2497 | list_del(&port_ptr->list); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2498 | up_write(&local_ports_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2499 | port_ptr->type = CONTROL_PORT; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2500 | down_write(&control_ports_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2501 | list_add_tail(&port_ptr->list, &control_ports); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2502 | up_write(&control_ports_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2503 | |
| 2504 | return 0; |
| 2505 | } |
| 2506 | |
| 2507 | int msm_ipc_router_lookup_server_name(struct msm_ipc_port_name *srv_name, |
Karthikeyan Ramasubramanian | dfde01b | 2012-06-12 14:25:13 -0600 | [diff] [blame] | 2508 | struct msm_ipc_server_info *srv_info, |
Karthikeyan Ramasubramanian | cc450c9 | 2011-07-27 14:38:15 -0600 | [diff] [blame] | 2509 | int num_entries_in_array, |
| 2510 | uint32_t lookup_mask) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2511 | { |
| 2512 | struct msm_ipc_server *server; |
| 2513 | struct msm_ipc_server_port *server_port; |
Karthikeyan Ramasubramanian | cc450c9 | 2011-07-27 14:38:15 -0600 | [diff] [blame] | 2514 | int key, i = 0; /*num_entries_found*/ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2515 | |
| 2516 | if (!srv_name) { |
| 2517 | pr_err("%s: Invalid srv_name\n", __func__); |
| 2518 | return -EINVAL; |
| 2519 | } |
| 2520 | |
Karthikeyan Ramasubramanian | dfde01b | 2012-06-12 14:25:13 -0600 | [diff] [blame] | 2521 | if (num_entries_in_array && !srv_info) { |
| 2522 | pr_err("%s: srv_info NULL\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2523 | return -EINVAL; |
| 2524 | } |
| 2525 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2526 | down_read(&server_list_lock_lha2); |
Karthikeyan Ramasubramanian | cc450c9 | 2011-07-27 14:38:15 -0600 | [diff] [blame] | 2527 | if (!lookup_mask) |
| 2528 | lookup_mask = 0xFFFFFFFF; |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 2529 | key = (srv_name->service & (SRV_HASH_SIZE - 1)); |
| 2530 | list_for_each_entry(server, &server_list[key], list) { |
| 2531 | if ((server->name.service != srv_name->service) || |
| 2532 | ((server->name.instance & lookup_mask) != |
| 2533 | srv_name->instance)) |
| 2534 | continue; |
Karthikeyan Ramasubramanian | cc450c9 | 2011-07-27 14:38:15 -0600 | [diff] [blame] | 2535 | |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 2536 | list_for_each_entry(server_port, |
| 2537 | &server->server_port_list, list) { |
| 2538 | if (i < num_entries_in_array) { |
| 2539 | srv_info[i].node_id = |
Karthikeyan Ramasubramanian | cc450c9 | 2011-07-27 14:38:15 -0600 | [diff] [blame] | 2540 | server_port->server_addr.node_id; |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 2541 | srv_info[i].port_id = |
Karthikeyan Ramasubramanian | cc450c9 | 2011-07-27 14:38:15 -0600 | [diff] [blame] | 2542 | server_port->server_addr.port_id; |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 2543 | srv_info[i].service = server->name.service; |
| 2544 | srv_info[i].instance = server->name.instance; |
Karthikeyan Ramasubramanian | cc450c9 | 2011-07-27 14:38:15 -0600 | [diff] [blame] | 2545 | } |
Karthikeyan Ramasubramanian | bb8306b | 2012-10-25 15:40:45 -0600 | [diff] [blame] | 2546 | i++; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2547 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2548 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2549 | up_read(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2550 | |
| 2551 | return i; |
| 2552 | } |
| 2553 | |
| 2554 | int msm_ipc_router_close(void) |
| 2555 | { |
| 2556 | struct msm_ipc_router_xprt_info *xprt_info, *tmp_xprt_info; |
| 2557 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2558 | down_write(&xprt_info_list_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2559 | list_for_each_entry_safe(xprt_info, tmp_xprt_info, |
| 2560 | &xprt_info_list, list) { |
Karthikeyan Ramasubramanian | 8cec592 | 2012-02-16 17:41:58 -0700 | [diff] [blame] | 2561 | xprt_info->xprt->close(xprt_info->xprt); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2562 | list_del(&xprt_info->list); |
| 2563 | kfree(xprt_info); |
| 2564 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2565 | up_write(&xprt_info_list_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2566 | return 0; |
| 2567 | } |
| 2568 | |
| 2569 | #if defined(CONFIG_DEBUG_FS) |
| 2570 | static int dump_routing_table(char *buf, int max) |
| 2571 | { |
| 2572 | int i = 0, j; |
| 2573 | struct msm_ipc_routing_table_entry *rt_entry; |
| 2574 | |
| 2575 | for (j = 0; j < RT_HASH_SIZE; j++) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2576 | down_read(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2577 | list_for_each_entry(rt_entry, &routing_table[j], list) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2578 | down_read(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2579 | i += scnprintf(buf + i, max - i, |
| 2580 | "Node Id: 0x%08x\n", rt_entry->node_id); |
Karthikeyan Ramasubramanian | bddeec7 | 2012-09-10 16:10:24 -0600 | [diff] [blame] | 2581 | if (rt_entry->node_id == IPC_ROUTER_NID_LOCAL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2582 | i += scnprintf(buf + i, max - i, |
| 2583 | "XPRT Name: Loopback\n"); |
| 2584 | i += scnprintf(buf + i, max - i, |
| 2585 | "Next Hop: %d\n", rt_entry->node_id); |
| 2586 | } else { |
| 2587 | i += scnprintf(buf + i, max - i, |
| 2588 | "XPRT Name: %s\n", |
| 2589 | rt_entry->xprt_info->xprt->name); |
| 2590 | i += scnprintf(buf + i, max - i, |
| 2591 | "Next Hop: 0x%08x\n", |
| 2592 | rt_entry->xprt_info->remote_node_id); |
| 2593 | } |
| 2594 | i += scnprintf(buf + i, max - i, "\n"); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2595 | up_read(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2596 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2597 | up_read(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | return i; |
| 2601 | } |
| 2602 | |
| 2603 | static int dump_xprt_info(char *buf, int max) |
| 2604 | { |
| 2605 | int i = 0; |
| 2606 | struct msm_ipc_router_xprt_info *xprt_info; |
| 2607 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2608 | down_read(&xprt_info_list_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2609 | list_for_each_entry(xprt_info, &xprt_info_list, list) { |
| 2610 | i += scnprintf(buf + i, max - i, "XPRT Name: %s\n", |
| 2611 | xprt_info->xprt->name); |
| 2612 | i += scnprintf(buf + i, max - i, "Link Id: %d\n", |
| 2613 | xprt_info->xprt->link_id); |
| 2614 | i += scnprintf(buf + i, max - i, "Initialized: %s\n", |
| 2615 | (xprt_info->initialized ? "Y" : "N")); |
| 2616 | i += scnprintf(buf + i, max - i, "Remote Node Id: 0x%08x\n", |
| 2617 | xprt_info->remote_node_id); |
| 2618 | i += scnprintf(buf + i, max - i, "\n"); |
| 2619 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2620 | up_read(&xprt_info_list_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2621 | |
| 2622 | return i; |
| 2623 | } |
| 2624 | |
| 2625 | static int dump_servers(char *buf, int max) |
| 2626 | { |
| 2627 | int i = 0, j; |
| 2628 | struct msm_ipc_server *server; |
| 2629 | struct msm_ipc_server_port *server_port; |
| 2630 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2631 | down_read(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2632 | for (j = 0; j < SRV_HASH_SIZE; j++) { |
| 2633 | list_for_each_entry(server, &server_list[j], list) { |
| 2634 | list_for_each_entry(server_port, |
| 2635 | &server->server_port_list, |
| 2636 | list) { |
| 2637 | i += scnprintf(buf + i, max - i, "Service: " |
| 2638 | "0x%08x\n", server->name.service); |
| 2639 | i += scnprintf(buf + i, max - i, "Instance: " |
| 2640 | "0x%08x\n", server->name.instance); |
| 2641 | i += scnprintf(buf + i, max - i, |
| 2642 | "Node_id: 0x%08x\n", |
| 2643 | server_port->server_addr.node_id); |
| 2644 | i += scnprintf(buf + i, max - i, |
| 2645 | "Port_id: 0x%08x\n", |
| 2646 | server_port->server_addr.port_id); |
| 2647 | i += scnprintf(buf + i, max - i, "\n"); |
| 2648 | } |
| 2649 | } |
| 2650 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2651 | up_read(&server_list_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2652 | |
| 2653 | return i; |
| 2654 | } |
| 2655 | |
| 2656 | static int dump_remote_ports(char *buf, int max) |
| 2657 | { |
| 2658 | int i = 0, j, k; |
| 2659 | struct msm_ipc_router_remote_port *rport_ptr; |
| 2660 | struct msm_ipc_routing_table_entry *rt_entry; |
| 2661 | |
| 2662 | for (j = 0; j < RT_HASH_SIZE; j++) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2663 | down_read(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2664 | list_for_each_entry(rt_entry, &routing_table[j], list) { |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2665 | down_read(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2666 | for (k = 0; k < RP_HASH_SIZE; k++) { |
| 2667 | list_for_each_entry(rport_ptr, |
| 2668 | &rt_entry->remote_port_list[k], |
| 2669 | list) { |
| 2670 | i += scnprintf(buf + i, max - i, |
| 2671 | "Node_id: 0x%08x\n", |
| 2672 | rport_ptr->node_id); |
| 2673 | i += scnprintf(buf + i, max - i, |
| 2674 | "Port_id: 0x%08x\n", |
| 2675 | rport_ptr->port_id); |
| 2676 | i += scnprintf(buf + i, max - i, |
| 2677 | "Quota_cnt: %d\n", |
| 2678 | rport_ptr->tx_quota_cnt); |
| 2679 | i += scnprintf(buf + i, max - i, "\n"); |
| 2680 | } |
| 2681 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2682 | up_read(&rt_entry->lock_lha4); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2683 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2684 | up_read(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | return i; |
| 2688 | } |
| 2689 | |
| 2690 | static int dump_control_ports(char *buf, int max) |
| 2691 | { |
| 2692 | int i = 0; |
| 2693 | struct msm_ipc_port *port_ptr; |
| 2694 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2695 | down_read(&control_ports_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2696 | list_for_each_entry(port_ptr, &control_ports, list) { |
| 2697 | i += scnprintf(buf + i, max - i, "Node_id: 0x%08x\n", |
| 2698 | port_ptr->this_port.node_id); |
| 2699 | i += scnprintf(buf + i, max - i, "Port_id: 0x%08x\n", |
| 2700 | port_ptr->this_port.port_id); |
| 2701 | i += scnprintf(buf + i, max - i, "\n"); |
| 2702 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2703 | up_read(&control_ports_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2704 | |
| 2705 | return i; |
| 2706 | } |
| 2707 | |
| 2708 | static int dump_local_ports(char *buf, int max) |
| 2709 | { |
| 2710 | int i = 0, j; |
| 2711 | unsigned long flags; |
| 2712 | struct msm_ipc_port *port_ptr; |
| 2713 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2714 | down_read(&local_ports_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2715 | for (j = 0; j < LP_HASH_SIZE; j++) { |
| 2716 | list_for_each_entry(port_ptr, &local_ports[j], list) { |
| 2717 | spin_lock_irqsave(&port_ptr->port_lock, flags); |
| 2718 | i += scnprintf(buf + i, max - i, "Node_id: 0x%08x\n", |
| 2719 | port_ptr->this_port.node_id); |
| 2720 | i += scnprintf(buf + i, max - i, "Port_id: 0x%08x\n", |
| 2721 | port_ptr->this_port.port_id); |
| 2722 | i += scnprintf(buf + i, max - i, "# pkts tx'd %d\n", |
| 2723 | port_ptr->num_tx); |
| 2724 | i += scnprintf(buf + i, max - i, "# pkts rx'd %d\n", |
| 2725 | port_ptr->num_rx); |
| 2726 | i += scnprintf(buf + i, max - i, "# bytes tx'd %ld\n", |
| 2727 | port_ptr->num_tx_bytes); |
| 2728 | i += scnprintf(buf + i, max - i, "# bytes rx'd %ld\n", |
| 2729 | port_ptr->num_rx_bytes); |
| 2730 | spin_unlock_irqrestore(&port_ptr->port_lock, flags); |
| 2731 | i += scnprintf(buf + i, max - i, "\n"); |
| 2732 | } |
| 2733 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2734 | up_read(&local_ports_lock_lha2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2735 | |
| 2736 | return i; |
| 2737 | } |
| 2738 | |
| 2739 | #define DEBUG_BUFMAX 4096 |
| 2740 | static char debug_buffer[DEBUG_BUFMAX]; |
| 2741 | |
| 2742 | static ssize_t debug_read(struct file *file, char __user *buf, |
| 2743 | size_t count, loff_t *ppos) |
| 2744 | { |
| 2745 | int (*fill)(char *buf, int max) = file->private_data; |
| 2746 | int bsize = fill(debug_buffer, DEBUG_BUFMAX); |
| 2747 | return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize); |
| 2748 | } |
| 2749 | |
| 2750 | static int debug_open(struct inode *inode, struct file *file) |
| 2751 | { |
| 2752 | file->private_data = inode->i_private; |
| 2753 | return 0; |
| 2754 | } |
| 2755 | |
| 2756 | static const struct file_operations debug_ops = { |
| 2757 | .read = debug_read, |
| 2758 | .open = debug_open, |
| 2759 | }; |
| 2760 | |
| 2761 | static void debug_create(const char *name, mode_t mode, |
| 2762 | struct dentry *dent, |
| 2763 | int (*fill)(char *buf, int max)) |
| 2764 | { |
| 2765 | debugfs_create_file(name, mode, dent, fill, &debug_ops); |
| 2766 | } |
| 2767 | |
| 2768 | static void debugfs_init(void) |
| 2769 | { |
| 2770 | struct dentry *dent; |
| 2771 | |
| 2772 | dent = debugfs_create_dir("msm_ipc_router", 0); |
| 2773 | if (IS_ERR(dent)) |
| 2774 | return; |
| 2775 | |
| 2776 | debug_create("dump_local_ports", 0444, dent, |
| 2777 | dump_local_ports); |
| 2778 | debug_create("dump_remote_ports", 0444, dent, |
| 2779 | dump_remote_ports); |
| 2780 | debug_create("dump_control_ports", 0444, dent, |
| 2781 | dump_control_ports); |
| 2782 | debug_create("dump_servers", 0444, dent, |
| 2783 | dump_servers); |
| 2784 | debug_create("dump_xprt_info", 0444, dent, |
| 2785 | dump_xprt_info); |
| 2786 | debug_create("dump_routing_table", 0444, dent, |
| 2787 | dump_routing_table); |
| 2788 | } |
| 2789 | |
| 2790 | #else |
| 2791 | static void debugfs_init(void) {} |
| 2792 | #endif |
| 2793 | |
| 2794 | static int msm_ipc_router_add_xprt(struct msm_ipc_router_xprt *xprt) |
| 2795 | { |
| 2796 | struct msm_ipc_router_xprt_info *xprt_info; |
| 2797 | struct msm_ipc_routing_table_entry *rt_entry; |
| 2798 | |
| 2799 | xprt_info = kmalloc(sizeof(struct msm_ipc_router_xprt_info), |
| 2800 | GFP_KERNEL); |
| 2801 | if (!xprt_info) |
| 2802 | return -ENOMEM; |
| 2803 | |
| 2804 | xprt_info->xprt = xprt; |
| 2805 | xprt_info->initialized = 0; |
| 2806 | xprt_info->remote_node_id = -1; |
| 2807 | INIT_LIST_HEAD(&xprt_info->pkt_list); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2808 | mutex_init(&xprt_info->rx_lock_lhb2); |
| 2809 | mutex_init(&xprt_info->tx_lock_lhb2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2810 | wake_lock_init(&xprt_info->wakelock, |
| 2811 | WAKE_LOCK_SUSPEND, xprt->name); |
| 2812 | xprt_info->need_len = 0; |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2813 | xprt_info->abort_data_read = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2814 | INIT_WORK(&xprt_info->read_data, do_read_data); |
| 2815 | INIT_LIST_HEAD(&xprt_info->list); |
| 2816 | |
| 2817 | xprt_info->workqueue = create_singlethread_workqueue(xprt->name); |
| 2818 | if (!xprt_info->workqueue) { |
| 2819 | kfree(xprt_info); |
| 2820 | return -ENOMEM; |
| 2821 | } |
| 2822 | |
| 2823 | if (!strcmp(xprt->name, "msm_ipc_router_loopback_xprt")) { |
| 2824 | xprt_info->remote_node_id = IPC_ROUTER_NID_LOCAL; |
| 2825 | xprt_info->initialized = 1; |
| 2826 | } |
| 2827 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2828 | down_write(&xprt_info_list_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2829 | list_add_tail(&xprt_info->list, &xprt_info_list); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2830 | up_write(&xprt_info_list_lock_lha5); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2831 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2832 | down_write(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2833 | if (!routing_table_inited) { |
| 2834 | init_routing_table(); |
| 2835 | rt_entry = alloc_routing_table_entry(IPC_ROUTER_NID_LOCAL); |
| 2836 | add_routing_table_entry(rt_entry); |
| 2837 | routing_table_inited = 1; |
| 2838 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2839 | up_write(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2840 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2841 | xprt->priv = xprt_info; |
| 2842 | |
| 2843 | return 0; |
| 2844 | } |
| 2845 | |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2846 | static void msm_ipc_router_remove_xprt(struct msm_ipc_router_xprt *xprt) |
| 2847 | { |
| 2848 | struct msm_ipc_router_xprt_info *xprt_info; |
| 2849 | |
| 2850 | if (xprt && xprt->priv) { |
| 2851 | xprt_info = xprt->priv; |
| 2852 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2853 | mutex_lock(&xprt_info->rx_lock_lhb2); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2854 | xprt_info->abort_data_read = 1; |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2855 | mutex_unlock(&xprt_info->rx_lock_lhb2); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2856 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2857 | down_write(&xprt_info_list_lock_lha5); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2858 | list_del(&xprt_info->list); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2859 | up_write(&xprt_info_list_lock_lha5); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2860 | |
| 2861 | flush_workqueue(xprt_info->workqueue); |
| 2862 | destroy_workqueue(xprt_info->workqueue); |
| 2863 | wake_lock_destroy(&xprt_info->wakelock); |
| 2864 | |
| 2865 | xprt->priv = 0; |
| 2866 | kfree(xprt_info); |
| 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | |
| 2871 | struct msm_ipc_router_xprt_work { |
| 2872 | struct msm_ipc_router_xprt *xprt; |
| 2873 | struct work_struct work; |
| 2874 | }; |
| 2875 | |
| 2876 | static void xprt_open_worker(struct work_struct *work) |
| 2877 | { |
| 2878 | struct msm_ipc_router_xprt_work *xprt_work = |
| 2879 | container_of(work, struct msm_ipc_router_xprt_work, work); |
| 2880 | |
| 2881 | msm_ipc_router_add_xprt(xprt_work->xprt); |
| 2882 | kfree(xprt_work); |
| 2883 | } |
| 2884 | |
| 2885 | static void xprt_close_worker(struct work_struct *work) |
| 2886 | { |
| 2887 | struct msm_ipc_router_xprt_work *xprt_work = |
| 2888 | container_of(work, struct msm_ipc_router_xprt_work, work); |
| 2889 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2890 | msm_ipc_cleanup_routing_table(xprt_work->xprt->priv); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2891 | msm_ipc_router_remove_xprt(xprt_work->xprt); |
Karthikeyan Ramasubramanian | e6ef0a2 | 2013-06-12 11:49:26 -0600 | [diff] [blame] | 2892 | xprt_work->xprt->sft_close_done(xprt_work->xprt); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2893 | kfree(xprt_work); |
| 2894 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2895 | |
| 2896 | void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt, |
| 2897 | unsigned event, |
| 2898 | void *data) |
| 2899 | { |
| 2900 | struct msm_ipc_router_xprt_info *xprt_info = xprt->priv; |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2901 | struct msm_ipc_router_xprt_work *xprt_work; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2902 | struct rr_packet *pkt; |
Karthikeyan Ramasubramanian | 4af9f7c | 2011-09-30 15:55:18 -0600 | [diff] [blame] | 2903 | unsigned long ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2904 | |
Karthikeyan Ramasubramanian | 4af9f7c | 2011-09-30 15:55:18 -0600 | [diff] [blame] | 2905 | if (!msm_ipc_router_workqueue) { |
| 2906 | ret = wait_for_completion_timeout(&msm_ipc_local_router_up, |
| 2907 | IPC_ROUTER_INIT_TIMEOUT); |
| 2908 | if (!ret || !msm_ipc_router_workqueue) { |
| 2909 | pr_err("%s: IPC Router not initialized\n", __func__); |
| 2910 | return; |
| 2911 | } |
| 2912 | } |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2913 | |
| 2914 | switch (event) { |
| 2915 | case IPC_ROUTER_XPRT_EVENT_OPEN: |
| 2916 | D("open event for '%s'\n", xprt->name); |
| 2917 | xprt_work = kmalloc(sizeof(struct msm_ipc_router_xprt_work), |
| 2918 | GFP_ATOMIC); |
Karthikeyan Ramasubramanian | 840bed1 | 2013-05-16 15:51:29 -0600 | [diff] [blame] | 2919 | if (xprt_work) { |
| 2920 | xprt_work->xprt = xprt; |
| 2921 | INIT_WORK(&xprt_work->work, xprt_open_worker); |
| 2922 | queue_work(msm_ipc_router_workqueue, &xprt_work->work); |
| 2923 | } else { |
| 2924 | pr_err("%s: malloc failure - Couldn't notify OPEN event", |
| 2925 | __func__); |
| 2926 | } |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2927 | break; |
| 2928 | |
| 2929 | case IPC_ROUTER_XPRT_EVENT_CLOSE: |
| 2930 | D("close event for '%s'\n", xprt->name); |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2931 | xprt_work = kmalloc(sizeof(struct msm_ipc_router_xprt_work), |
| 2932 | GFP_ATOMIC); |
Karthikeyan Ramasubramanian | 840bed1 | 2013-05-16 15:51:29 -0600 | [diff] [blame] | 2933 | if (xprt_work) { |
| 2934 | xprt_work->xprt = xprt; |
| 2935 | INIT_WORK(&xprt_work->work, xprt_close_worker); |
| 2936 | queue_work(msm_ipc_router_workqueue, &xprt_work->work); |
| 2937 | } else { |
| 2938 | pr_err("%s: malloc failure - Couldn't notify CLOSE event", |
| 2939 | __func__); |
| 2940 | } |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2941 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | if (!data) |
| 2945 | return; |
| 2946 | |
| 2947 | while (!xprt_info) { |
| 2948 | msleep(100); |
| 2949 | xprt_info = xprt->priv; |
| 2950 | } |
| 2951 | |
| 2952 | pkt = clone_pkt((struct rr_packet *)data); |
| 2953 | if (!pkt) |
| 2954 | return; |
| 2955 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2956 | mutex_lock(&xprt_info->rx_lock_lhb2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2957 | list_add_tail(&pkt->list, &xprt_info->pkt_list); |
| 2958 | wake_lock(&xprt_info->wakelock); |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2959 | mutex_unlock(&xprt_info->rx_lock_lhb2); |
Karthikeyan Ramasubramanian | 872ecd8 | 2012-07-25 11:07:48 -0600 | [diff] [blame] | 2960 | queue_work(xprt_info->workqueue, &xprt_info->read_data); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | static int __init msm_ipc_router_init(void) |
| 2964 | { |
| 2965 | int i, ret; |
| 2966 | struct msm_ipc_routing_table_entry *rt_entry; |
| 2967 | |
| 2968 | msm_ipc_router_debug_mask |= SMEM_LOG; |
Karthikeyan Ramasubramanian | 2bfe8ec | 2013-03-22 10:47:20 -0600 | [diff] [blame] | 2969 | ipc_rtr_log_ctxt = ipc_log_context_create(IPC_RTR_LOG_PAGES, |
| 2970 | "ipc_router"); |
| 2971 | if (!ipc_rtr_log_ctxt) |
| 2972 | pr_err("%s: Unable to create IPC logging for IPC RTR", |
| 2973 | __func__); |
| 2974 | |
Karthikeyan Ramasubramanian | ff6fbae | 2011-06-09 11:13:19 -0600 | [diff] [blame] | 2975 | msm_ipc_router_workqueue = |
| 2976 | create_singlethread_workqueue("msm_ipc_router"); |
| 2977 | if (!msm_ipc_router_workqueue) |
| 2978 | return -ENOMEM; |
| 2979 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2980 | debugfs_init(); |
| 2981 | |
| 2982 | for (i = 0; i < SRV_HASH_SIZE; i++) |
| 2983 | INIT_LIST_HEAD(&server_list[i]); |
| 2984 | |
| 2985 | for (i = 0; i < LP_HASH_SIZE; i++) |
| 2986 | INIT_LIST_HEAD(&local_ports[i]); |
| 2987 | |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2988 | down_write(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2989 | if (!routing_table_inited) { |
| 2990 | init_routing_table(); |
| 2991 | rt_entry = alloc_routing_table_entry(IPC_ROUTER_NID_LOCAL); |
| 2992 | add_routing_table_entry(rt_entry); |
| 2993 | routing_table_inited = 1; |
| 2994 | } |
Karthikeyan Ramasubramanian | 4b88e5d | 2013-05-21 11:49:21 -0600 | [diff] [blame] | 2995 | up_write(&routing_table_lock_lha3); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2996 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2997 | ret = msm_ipc_router_init_sockets(); |
| 2998 | if (ret < 0) |
| 2999 | pr_err("%s: Init sockets failed\n", __func__); |
| 3000 | |
Karthikeyan Ramasubramanian | 5b502d364 | 2012-09-23 22:23:36 -0600 | [diff] [blame] | 3001 | ret = msm_ipc_router_security_init(); |
| 3002 | if (ret < 0) |
| 3003 | pr_err("%s: Security Init failed\n", __func__); |
| 3004 | |
Karthikeyan Ramasubramanian | 4af9f7c | 2011-09-30 15:55:18 -0600 | [diff] [blame] | 3005 | complete_all(&msm_ipc_local_router_up); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3006 | return ret; |
| 3007 | } |
| 3008 | |
| 3009 | module_init(msm_ipc_router_init); |
| 3010 | MODULE_DESCRIPTION("MSM IPC Router"); |
| 3011 | MODULE_LICENSE("GPL v2"); |