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