blob: ef763d7ad32596e6444d2d6efa3d9101bee8211a [file] [log] [blame]
Karthikeyan Ramasubramanian25e91872013-01-10 17:09:13 -07001/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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 Ramasubramaniand06fe072013-05-21 11:49:21 -060030#include <linux/rwsem.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031
32#include <asm/uaccess.h>
33#include <asm/byteorder.h>
34
35#include <mach/smem_log.h>
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -060036#include <mach/subsystem_notif.h>
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -060037#include <mach/msm_ipc_router.h>
Karthikeyan Ramasubramanian682ebcc2013-03-22 10:47:20 -060038#include <mach/msm_ipc_logging.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039
40#include "ipc_router.h"
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -060041#include "modem_notifier.h"
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -060042#include "msm_ipc_router_security.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070043
44enum {
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
53static int msm_ipc_router_debug_mask;
54module_param_named(debug_mask, msm_ipc_router_debug_mask,
55 int, S_IRUGO | S_IWUSR | S_IWGRP);
56
Karthikeyan Ramasubramanian682ebcc2013-03-22 10:47:20 -060057static void *ipc_rtr_log_ctxt;
58#define IPC_RTR_LOG_PAGES 5
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059#define DIAG(x...) pr_info("[RR] ERROR " x)
60
61#if defined(DEBUG)
62#define D(x...) do { \
Karthikeyan Ramasubramanian682ebcc2013-03-22 10:47:20 -060063if (ipc_rtr_log_ctxt) \
64 ipc_log_string(ipc_rtr_log_ctxt, x); \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070065if (msm_ipc_router_debug_mask & RTR_DBG) \
66 pr_info(x); \
67} while (0)
68
69#define RR(x...) do { \
Karthikeyan Ramasubramanian682ebcc2013-03-22 10:47:20 -060070if (ipc_rtr_log_ctxt) \
71 ipc_log_string(ipc_rtr_log_ctxt, x); \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070072if (msm_ipc_router_debug_mask & R2R_MSG) \
73 pr_info("[RR] "x); \
74} while (0)
75
76#define RAW(x...) do { \
77if (msm_ipc_router_debug_mask & R2R_RAW) \
78 pr_info("[RAW] "x); \
79} while (0)
80
81#define NTFY(x...) do { \
82if (msm_ipc_router_debug_mask & NTFY_MSG) \
83 pr_info("[NOTIFY] "x); \
84} while (0)
85
86#define RAW_HDR(x...) do { \
87if (msm_ipc_router_debug_mask & R2R_RAW_HDR) \
88 pr_info("[HDR] "x); \
89} while (0)
90#else
91#define D(x...) do { } while (0)
92#define RR(x...) do { } while (0)
93#define RAW(x...) do { } while (0)
94#define RAW_HDR(x...) do { } while (0)
95#define NTFY(x...) do { } while (0)
96#endif
97
98#define IPC_ROUTER_LOG_EVENT_ERROR 0x10
99#define IPC_ROUTER_LOG_EVENT_TX 0x11
100#define IPC_ROUTER_LOG_EVENT_RX 0x12
101
102static LIST_HEAD(control_ports);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600103static DECLARE_RWSEM(control_ports_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700104
105#define LP_HASH_SIZE 32
106static struct list_head local_ports[LP_HASH_SIZE];
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600107static DECLARE_RWSEM(local_ports_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700108
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -0600109/*
110 * Server info is organized as a hash table. The server's service ID is
111 * used to index into the hash table. The instance ID of most of the servers
112 * are 1 or 2. The service IDs are well distributed compared to the instance
113 * IDs and hence choosing service ID to index into this hash table optimizes
114 * the hash table operations like add, lookup, destroy.
115 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116#define SRV_HASH_SIZE 32
117static struct list_head server_list[SRV_HASH_SIZE];
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600118static DECLARE_RWSEM(server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700119
120struct msm_ipc_server {
121 struct list_head list;
122 struct msm_ipc_port_name name;
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -0600123 int synced_sec_rule;
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -0600124 char pdev_name[32];
125 int next_pdev_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700126 struct list_head server_port_list;
127};
128
129struct msm_ipc_server_port {
130 struct list_head list;
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -0600131 struct platform_device pdev;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700132 struct msm_ipc_port_addr server_addr;
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -0600133 struct msm_ipc_router_xprt_info *xprt_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700134};
135
Zaheerulla Meera34fc662013-04-17 01:16:47 +0530136struct msm_ipc_resume_tx_port {
137 struct list_head list;
138 uint32_t port_id;
139 uint32_t node_id;
140};
141
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700142#define RP_HASH_SIZE 32
143struct msm_ipc_router_remote_port {
144 struct list_head list;
145 uint32_t node_id;
146 uint32_t port_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147 uint32_t tx_quota_cnt;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600148 struct mutex quota_lock_lhb2;
Zaheerulla Meera34fc662013-04-17 01:16:47 +0530149 struct list_head resume_tx_port_list;
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -0600150 void *sec_rule;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600151 struct msm_ipc_server *server;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700152};
153
154struct msm_ipc_router_xprt_info {
155 struct list_head list;
156 struct msm_ipc_router_xprt *xprt;
157 uint32_t remote_node_id;
158 uint32_t initialized;
159 struct list_head pkt_list;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700160 struct wake_lock wakelock;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600161 struct mutex rx_lock_lhb2;
162 struct mutex tx_lock_lhb2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700163 uint32_t need_len;
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -0600164 uint32_t abort_data_read;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700165 struct work_struct read_data;
166 struct workqueue_struct *workqueue;
167};
168
169#define RT_HASH_SIZE 4
170struct msm_ipc_routing_table_entry {
171 struct list_head list;
172 uint32_t node_id;
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -0600173 uint32_t neighbor_node_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174 struct list_head remote_port_list[RP_HASH_SIZE];
175 struct msm_ipc_router_xprt_info *xprt_info;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600176 struct rw_semaphore lock_lha4;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700177 unsigned long num_tx_bytes;
178 unsigned long num_rx_bytes;
179};
180
181static struct list_head routing_table[RT_HASH_SIZE];
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600182static DECLARE_RWSEM(routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700183static int routing_table_inited;
184
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185static void do_read_data(struct work_struct *work);
186
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187static LIST_HEAD(xprt_info_list);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600188static DECLARE_RWSEM(xprt_info_list_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189
Karthikeyan Ramasubramanian4af9f7c2011-09-30 15:55:18 -0600190static DECLARE_COMPLETION(msm_ipc_local_router_up);
191#define IPC_ROUTER_INIT_TIMEOUT (10 * HZ)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700192
193static uint32_t next_port_id;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600194static DEFINE_MUTEX(next_port_id_lock_lha1);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -0600195static struct workqueue_struct *msm_ipc_router_workqueue;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700196
197enum {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700198 DOWN,
199 UP,
200};
201
202static void init_routing_table(void)
203{
204 int i;
205 for (i = 0; i < RT_HASH_SIZE; i++)
206 INIT_LIST_HEAD(&routing_table[i]);
207}
208
209static struct msm_ipc_routing_table_entry *alloc_routing_table_entry(
210 uint32_t node_id)
211{
212 int i;
213 struct msm_ipc_routing_table_entry *rt_entry;
214
215 rt_entry = kmalloc(sizeof(struct msm_ipc_routing_table_entry),
216 GFP_KERNEL);
217 if (!rt_entry) {
218 pr_err("%s: rt_entry allocation failed for %d\n",
219 __func__, node_id);
220 return NULL;
221 }
222
223 for (i = 0; i < RP_HASH_SIZE; i++)
224 INIT_LIST_HEAD(&rt_entry->remote_port_list[i]);
225
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600226 init_rwsem(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700227 rt_entry->node_id = node_id;
228 rt_entry->xprt_info = NULL;
229 return rt_entry;
230}
231
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600232/* Must be called with routing_table_lock_lha3 locked. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700233static int add_routing_table_entry(
234 struct msm_ipc_routing_table_entry *rt_entry)
235{
236 uint32_t key;
237
238 if (!rt_entry)
239 return -EINVAL;
240
241 key = (rt_entry->node_id % RT_HASH_SIZE);
242 list_add_tail(&rt_entry->list, &routing_table[key]);
243 return 0;
244}
245
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600246/* Must be called with routing_table_lock_lha3 locked. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700247static struct msm_ipc_routing_table_entry *lookup_routing_table(
248 uint32_t node_id)
249{
250 uint32_t key = (node_id % RT_HASH_SIZE);
251 struct msm_ipc_routing_table_entry *rt_entry;
252
253 list_for_each_entry(rt_entry, &routing_table[key], list) {
254 if (rt_entry->node_id == node_id)
255 return rt_entry;
256 }
257 return NULL;
258}
259
260struct rr_packet *rr_read(struct msm_ipc_router_xprt_info *xprt_info)
261{
262 struct rr_packet *temp_pkt;
263
264 if (!xprt_info)
265 return NULL;
266
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600267 mutex_lock(&xprt_info->rx_lock_lhb2);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -0600268 if (xprt_info->abort_data_read) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600269 mutex_unlock(&xprt_info->rx_lock_lhb2);
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -0600270 pr_err("%s detected SSR & exiting now\n",
271 xprt_info->xprt->name);
272 return NULL;
273 }
274
275 if (list_empty(&xprt_info->pkt_list)) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600276 mutex_unlock(&xprt_info->rx_lock_lhb2);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -0600277 return NULL;
278 }
279
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700280 temp_pkt = list_first_entry(&xprt_info->pkt_list,
281 struct rr_packet, list);
282 list_del(&temp_pkt->list);
283 if (list_empty(&xprt_info->pkt_list))
284 wake_unlock(&xprt_info->wakelock);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600285 mutex_unlock(&xprt_info->rx_lock_lhb2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700286 return temp_pkt;
287}
288
289struct rr_packet *clone_pkt(struct rr_packet *pkt)
290{
291 struct rr_packet *cloned_pkt;
292 struct sk_buff *temp_skb, *cloned_skb;
293 struct sk_buff_head *pkt_fragment_q;
294
295 cloned_pkt = kzalloc(sizeof(struct rr_packet), GFP_KERNEL);
296 if (!cloned_pkt) {
297 pr_err("%s: failure\n", __func__);
298 return NULL;
299 }
300
301 pkt_fragment_q = kmalloc(sizeof(struct sk_buff_head), GFP_KERNEL);
302 if (!pkt_fragment_q) {
303 pr_err("%s: pkt_frag_q alloc failure\n", __func__);
304 kfree(cloned_pkt);
305 return NULL;
306 }
307 skb_queue_head_init(pkt_fragment_q);
308
309 skb_queue_walk(pkt->pkt_fragment_q, temp_skb) {
310 cloned_skb = skb_clone(temp_skb, GFP_KERNEL);
311 if (!cloned_skb)
312 goto fail_clone;
313 skb_queue_tail(pkt_fragment_q, cloned_skb);
314 }
315 cloned_pkt->pkt_fragment_q = pkt_fragment_q;
316 cloned_pkt->length = pkt->length;
317 return cloned_pkt;
318
319fail_clone:
320 while (!skb_queue_empty(pkt_fragment_q)) {
321 temp_skb = skb_dequeue(pkt_fragment_q);
322 kfree_skb(temp_skb);
323 }
324 kfree(pkt_fragment_q);
325 kfree(cloned_pkt);
326 return NULL;
327}
328
329struct rr_packet *create_pkt(struct sk_buff_head *data)
330{
331 struct rr_packet *pkt;
332 struct sk_buff *temp_skb;
333
334 pkt = kzalloc(sizeof(struct rr_packet), GFP_KERNEL);
335 if (!pkt) {
336 pr_err("%s: failure\n", __func__);
337 return NULL;
338 }
339
340 pkt->pkt_fragment_q = data;
341 skb_queue_walk(pkt->pkt_fragment_q, temp_skb)
342 pkt->length += temp_skb->len;
343 return pkt;
344}
345
346void release_pkt(struct rr_packet *pkt)
347{
348 struct sk_buff *temp_skb;
349
350 if (!pkt)
351 return;
352
353 if (!pkt->pkt_fragment_q) {
354 kfree(pkt);
355 return;
356 }
357
358 while (!skb_queue_empty(pkt->pkt_fragment_q)) {
359 temp_skb = skb_dequeue(pkt->pkt_fragment_q);
360 kfree_skb(temp_skb);
361 }
362 kfree(pkt->pkt_fragment_q);
363 kfree(pkt);
364 return;
365}
366
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -0600367static struct sk_buff_head *msm_ipc_router_buf_to_skb(void *buf,
368 unsigned int buf_len)
369{
370 struct sk_buff_head *skb_head;
371 struct sk_buff *skb;
372 int first = 1, offset = 0;
373 int skb_size, data_size;
374 void *data;
375
376 skb_head = kmalloc(sizeof(struct sk_buff_head), GFP_KERNEL);
377 if (!skb_head) {
378 pr_err("%s: Couldnot allocate skb_head\n", __func__);
379 return NULL;
380 }
381 skb_queue_head_init(skb_head);
382
383 data_size = buf_len;
384 while (offset != buf_len) {
385 skb_size = data_size;
386 if (first)
387 skb_size += IPC_ROUTER_HDR_SIZE;
388
389 skb = alloc_skb(skb_size, GFP_KERNEL);
390 if (!skb) {
391 if (skb_size <= (PAGE_SIZE/2)) {
392 pr_err("%s: cannot allocate skb\n", __func__);
393 goto buf_to_skb_error;
394 }
395 data_size = data_size / 2;
396 continue;
397 }
398
399 if (first) {
400 skb_reserve(skb, IPC_ROUTER_HDR_SIZE);
401 first = 0;
402 }
403
404 data = skb_put(skb, data_size);
405 memcpy(skb->data, buf + offset, data_size);
406 skb_queue_tail(skb_head, skb);
407 offset += data_size;
408 data_size = buf_len - offset;
409 }
410 return skb_head;
411
412buf_to_skb_error:
413 while (!skb_queue_empty(skb_head)) {
414 skb = skb_dequeue(skb_head);
415 kfree_skb(skb);
416 }
417 kfree(skb_head);
418 return NULL;
419}
420
421static void *msm_ipc_router_skb_to_buf(struct sk_buff_head *skb_head,
422 unsigned int len)
423{
424 struct sk_buff *temp;
425 int offset = 0, buf_len = 0, copy_len;
426 void *buf;
427
428 if (!skb_head) {
429 pr_err("%s: NULL skb_head\n", __func__);
430 return NULL;
431 }
432
433 temp = skb_peek(skb_head);
434 buf_len = len;
435 buf = kmalloc(buf_len, GFP_KERNEL);
436 if (!buf) {
437 pr_err("%s: cannot allocate buf\n", __func__);
438 return NULL;
439 }
440 skb_queue_walk(skb_head, temp) {
441 copy_len = buf_len < temp->len ? buf_len : temp->len;
442 memcpy(buf + offset, temp->data, copy_len);
443 offset += copy_len;
444 buf_len -= copy_len;
445 }
446 return buf;
447}
448
449static void msm_ipc_router_free_skb(struct sk_buff_head *skb_head)
450{
451 struct sk_buff *temp_skb;
452
453 if (!skb_head)
454 return;
455
456 while (!skb_queue_empty(skb_head)) {
457 temp_skb = skb_dequeue(skb_head);
458 kfree_skb(temp_skb);
459 }
460 kfree(skb_head);
461}
462
Karthikeyan Ramasubramaniand1af6252013-05-17 15:19:56 -0600463static int post_pkt_to_port(struct msm_ipc_port *port_ptr,
464 struct rr_packet *pkt, int clone)
465{
466 struct rr_packet *temp_pkt = pkt;
Zaheerulla Meer29302cf2013-05-24 21:19:18 +0530467 void (*notify)(unsigned event, void *priv);
Karthikeyan Ramasubramaniand1af6252013-05-17 15:19:56 -0600468
469 if (unlikely(!port_ptr || !pkt))
470 return -EINVAL;
471
472 if (clone) {
473 temp_pkt = clone_pkt(pkt);
474 if (!temp_pkt) {
475 pr_err("%s: Error cloning packet for port %08x:%08x\n",
476 __func__, port_ptr->this_port.node_id,
477 port_ptr->this_port.port_id);
478 return -ENOMEM;
479 }
480 }
481
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600482 mutex_lock(&port_ptr->port_rx_q_lock_lhb3);
Karthikeyan Ramasubramaniand1af6252013-05-17 15:19:56 -0600483 wake_lock(&port_ptr->port_rx_wake_lock);
484 list_add_tail(&temp_pkt->list, &port_ptr->port_rx_q);
485 wake_up(&port_ptr->port_rx_wait_q);
Zaheerulla Meer29302cf2013-05-24 21:19:18 +0530486 notify = port_ptr->notify;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600487 mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
Zaheerulla Meer29302cf2013-05-24 21:19:18 +0530488 if (notify)
489 notify(MSM_IPC_ROUTER_READ_CB, port_ptr->priv);
Karthikeyan Ramasubramaniand1af6252013-05-17 15:19:56 -0600490 return 0;
491}
492
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700493static int post_control_ports(struct rr_packet *pkt)
494{
495 struct msm_ipc_port *port_ptr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700496
497 if (!pkt)
498 return -EINVAL;
499
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600500 down_read(&control_ports_lock_lha5);
Karthikeyan Ramasubramaniand1af6252013-05-17 15:19:56 -0600501 list_for_each_entry(port_ptr, &control_ports, list)
502 post_pkt_to_port(port_ptr, pkt, 1);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600503 up_read(&control_ports_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700504 return 0;
505}
506
507static uint32_t allocate_port_id(void)
508{
509 uint32_t port_id = 0, prev_port_id, key;
510 struct msm_ipc_port *port_ptr;
511
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600512 mutex_lock(&next_port_id_lock_lha1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700513 prev_port_id = next_port_id;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600514 down_read(&local_ports_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700515 do {
516 next_port_id++;
517 if ((next_port_id & 0xFFFFFFFE) == 0xFFFFFFFE)
518 next_port_id = 1;
519
520 key = (next_port_id & (LP_HASH_SIZE - 1));
521 if (list_empty(&local_ports[key])) {
522 port_id = next_port_id;
523 break;
524 }
525 list_for_each_entry(port_ptr, &local_ports[key], list) {
526 if (port_ptr->this_port.port_id == next_port_id) {
527 port_id = next_port_id;
528 break;
529 }
530 }
531 if (!port_id) {
532 port_id = next_port_id;
533 break;
534 }
535 port_id = 0;
536 } while (next_port_id != prev_port_id);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600537 up_read(&local_ports_lock_lha2);
538 mutex_unlock(&next_port_id_lock_lha1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700539
540 return port_id;
541}
542
543void msm_ipc_router_add_local_port(struct msm_ipc_port *port_ptr)
544{
545 uint32_t key;
546
547 if (!port_ptr)
548 return;
549
550 key = (port_ptr->this_port.port_id & (LP_HASH_SIZE - 1));
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600551 down_write(&local_ports_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700552 list_add_tail(&port_ptr->list, &local_ports[key]);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600553 up_write(&local_ports_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700554}
555
556struct msm_ipc_port *msm_ipc_router_create_raw_port(void *endpoint,
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -0600557 void (*notify)(unsigned event, void *priv),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700558 void *priv)
559{
560 struct msm_ipc_port *port_ptr;
561
562 port_ptr = kzalloc(sizeof(struct msm_ipc_port), GFP_KERNEL);
563 if (!port_ptr)
564 return NULL;
565
566 port_ptr->this_port.node_id = IPC_ROUTER_NID_LOCAL;
567 port_ptr->this_port.port_id = allocate_port_id();
568 if (!port_ptr->this_port.port_id) {
569 pr_err("%s: All port ids are in use\n", __func__);
570 kfree(port_ptr);
571 return NULL;
572 }
573
574 spin_lock_init(&port_ptr->port_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700575 INIT_LIST_HEAD(&port_ptr->port_rx_q);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600576 mutex_init(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700577 init_waitqueue_head(&port_ptr->port_rx_wait_q);
Karthikeyan Ramasubramanianb4aeeb92012-03-13 12:31:43 -0600578 snprintf(port_ptr->rx_wakelock_name, MAX_WAKELOCK_NAME_SZ,
Karthikeyan Ramasubramanian090486e2013-02-14 13:53:20 -0700579 "ipc%08x_%s",
580 port_ptr->this_port.port_id,
581 current->comm);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700582 wake_lock_init(&port_ptr->port_rx_wake_lock,
Karthikeyan Ramasubramanianb4aeeb92012-03-13 12:31:43 -0600583 WAKE_LOCK_SUSPEND, port_ptr->rx_wakelock_name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700584
585 port_ptr->endpoint = endpoint;
586 port_ptr->notify = notify;
587 port_ptr->priv = priv;
588
589 msm_ipc_router_add_local_port(port_ptr);
590 return port_ptr;
591}
592
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600593/* Must be called with local_ports_lock_lha2 locked. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700594static struct msm_ipc_port *msm_ipc_router_lookup_local_port(uint32_t port_id)
595{
596 int key = (port_id & (LP_HASH_SIZE - 1));
597 struct msm_ipc_port *port_ptr;
598
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700599 list_for_each_entry(port_ptr, &local_ports[key], list) {
600 if (port_ptr->this_port.port_id == port_id) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700601 return port_ptr;
602 }
603 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700604 return NULL;
605}
606
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600607/* Must be called with routing_table_lock_lha3 locked. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700608static struct msm_ipc_router_remote_port *msm_ipc_router_lookup_remote_port(
609 uint32_t node_id,
610 uint32_t port_id)
611{
612 struct msm_ipc_router_remote_port *rport_ptr;
613 struct msm_ipc_routing_table_entry *rt_entry;
614 int key = (port_id & (RP_HASH_SIZE - 1));
615
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700616 rt_entry = lookup_routing_table(node_id);
617 if (!rt_entry) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700618 pr_err("%s: Node is not up\n", __func__);
619 return NULL;
620 }
621
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600622 down_read(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700623 list_for_each_entry(rport_ptr,
624 &rt_entry->remote_port_list[key], list) {
625 if (rport_ptr->port_id == port_id) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600626 up_read(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700627 return rport_ptr;
628 }
629 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600630 up_read(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700631 return NULL;
632}
633
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600634/* Must be called with routing_table_lock_lha3 locked. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700635static struct msm_ipc_router_remote_port *msm_ipc_router_create_remote_port(
636 uint32_t node_id,
637 uint32_t port_id)
638{
639 struct msm_ipc_router_remote_port *rport_ptr;
640 struct msm_ipc_routing_table_entry *rt_entry;
641 int key = (port_id & (RP_HASH_SIZE - 1));
642
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700643 rt_entry = lookup_routing_table(node_id);
644 if (!rt_entry) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700645 pr_err("%s: Node is not up\n", __func__);
646 return NULL;
647 }
648
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700649 rport_ptr = kmalloc(sizeof(struct msm_ipc_router_remote_port),
650 GFP_KERNEL);
651 if (!rport_ptr) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700652 pr_err("%s: Remote port alloc failed\n", __func__);
653 return NULL;
654 }
655 rport_ptr->port_id = port_id;
656 rport_ptr->node_id = node_id;
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -0600657 rport_ptr->sec_rule = NULL;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600658 rport_ptr->server = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700659 rport_ptr->tx_quota_cnt = 0;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600660 mutex_init(&rport_ptr->quota_lock_lhb2);
Zaheerulla Meera34fc662013-04-17 01:16:47 +0530661 INIT_LIST_HEAD(&rport_ptr->resume_tx_port_list);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600662 down_write(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700663 list_add_tail(&rport_ptr->list,
664 &rt_entry->remote_port_list[key]);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600665 up_write(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700666 return rport_ptr;
667}
668
Zaheerulla Meera34fc662013-04-17 01:16:47 +0530669/**
670 * msm_ipc_router_free_resume_tx_port() - Free the resume_tx ports
671 * @rport_ptr: Pointer to the remote port.
672 *
673 * This function deletes all the resume_tx ports associated with a remote port
674 * and frees the memory allocated to each resume_tx port.
675 *
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600676 * Must be called with rport_ptr->quota_lock_lhb2 locked.
Zaheerulla Meera34fc662013-04-17 01:16:47 +0530677 */
678static void msm_ipc_router_free_resume_tx_port(
679 struct msm_ipc_router_remote_port *rport_ptr)
680{
681 struct msm_ipc_resume_tx_port *rtx_port, *tmp_rtx_port;
682
683 list_for_each_entry_safe(rtx_port, tmp_rtx_port,
684 &rport_ptr->resume_tx_port_list, list) {
685 list_del(&rtx_port->list);
686 kfree(rtx_port);
687 }
688}
689
690/**
691 * msm_ipc_router_lookup_resume_tx_port() - Lookup resume_tx port list
692 * @rport_ptr: Remote port whose resume_tx port list needs to be looked.
693 * @port_id: Port ID which needs to be looked from the list.
694 *
695 * return 1 if the port_id is found in the list, else 0.
696 *
697 * This function is used to lookup the existence of a local port in
698 * remote port's resume_tx list. This function is used to ensure that
699 * the same port is not added to the remote_port's resume_tx list repeatedly.
700 *
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600701 * Must be called with rport_ptr->quota_lock_lhb2 locked.
Zaheerulla Meera34fc662013-04-17 01:16:47 +0530702 */
703static int msm_ipc_router_lookup_resume_tx_port(
704 struct msm_ipc_router_remote_port *rport_ptr, uint32_t port_id)
705{
706 struct msm_ipc_resume_tx_port *rtx_port;
707
708 list_for_each_entry(rtx_port, &rport_ptr->resume_tx_port_list, list) {
709 if (port_id == rtx_port->port_id)
710 return 1;
711 }
712 return 0;
713}
714
715/**
716 * post_resume_tx() - Post the resume_tx event
717 * @rport_ptr: Pointer to the remote port
718 * @pkt : The data packet that is received on a resume_tx event
719 *
720 * This function informs about the reception of the resume_tx message from a
721 * remote port pointed by rport_ptr to all the local ports that are in the
722 * resume_tx_ports_list of this remote port. On posting the information, this
723 * function sequentially deletes each entry in the resume_tx_port_list of the
724 * remote port.
725 *
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600726 * Must be called with rport_ptr->quota_lock_lhb2 locked.
Zaheerulla Meera34fc662013-04-17 01:16:47 +0530727 */
728static void post_resume_tx(struct msm_ipc_router_remote_port *rport_ptr,
729 struct rr_packet *pkt)
730{
731 struct msm_ipc_resume_tx_port *rtx_port, *tmp_rtx_port;
732 struct msm_ipc_port *local_port;
Zaheerulla Meera34fc662013-04-17 01:16:47 +0530733
734 list_for_each_entry_safe(rtx_port, tmp_rtx_port,
735 &rport_ptr->resume_tx_port_list, list) {
Zaheerulla Meera34fc662013-04-17 01:16:47 +0530736 local_port =
737 msm_ipc_router_lookup_local_port(rtx_port->port_id);
Karthikeyan Ramasubramaniand1af6252013-05-17 15:19:56 -0600738 if (local_port)
739 post_pkt_to_port(local_port, pkt, 1);
Zaheerulla Meera34fc662013-04-17 01:16:47 +0530740 list_del(&rtx_port->list);
741 kfree(rtx_port);
742 }
743}
744
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600745/* Must be called with routing_table_lock_lha3 locked. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700746static void msm_ipc_router_destroy_remote_port(
747 struct msm_ipc_router_remote_port *rport_ptr)
748{
749 uint32_t node_id;
750 struct msm_ipc_routing_table_entry *rt_entry;
751
752 if (!rport_ptr)
753 return;
754
755 node_id = rport_ptr->node_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700756 rt_entry = lookup_routing_table(node_id);
757 if (!rt_entry) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700758 pr_err("%s: Node %d is not up\n", __func__, node_id);
759 return;
760 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600761 down_write(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700762 list_del(&rport_ptr->list);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600763 up_write(&rt_entry->lock_lha4);
764 mutex_lock(&rport_ptr->quota_lock_lhb2);
765 msm_ipc_router_free_resume_tx_port(rport_ptr);
766 mutex_unlock(&rport_ptr->quota_lock_lhb2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700767 kfree(rport_ptr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700768 return;
769}
770
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -0600771/**
772 * msm_ipc_router_lookup_server() - Lookup server information
773 * @service: Service ID of the server info to be looked up.
774 * @instance: Instance ID of the server info to be looked up.
775 * @node_id: Node/Processor ID in which the server is hosted.
776 * @port_id: Port ID within the node in which the server is hosted.
777 *
778 * @return: If found Pointer to server structure, else NULL.
779 *
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600780 * Note1: Lock the server_list_lock_lha2 before accessing this function.
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -0600781 * Note2: If the <node_id:port_id> are <0:0>, then the lookup is restricted
782 * to <service:instance>. Used only when a client wants to send a
783 * message to any QMI server.
784 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700785static struct msm_ipc_server *msm_ipc_router_lookup_server(
786 uint32_t service,
787 uint32_t instance,
788 uint32_t node_id,
789 uint32_t port_id)
790{
791 struct msm_ipc_server *server;
792 struct msm_ipc_server_port *server_port;
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -0600793 int key = (service & (SRV_HASH_SIZE - 1));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700794
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700795 list_for_each_entry(server, &server_list[key], list) {
796 if ((server->name.service != service) ||
797 (server->name.instance != instance))
798 continue;
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -0600799 if ((node_id == 0) && (port_id == 0))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700800 return server;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700801 list_for_each_entry(server_port, &server->server_port_list,
802 list) {
803 if ((server_port->server_addr.node_id == node_id) &&
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -0600804 (server_port->server_addr.port_id == port_id))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700805 return server;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700806 }
807 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700808 return NULL;
809}
810
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -0600811static void dummy_release(struct device *dev)
812{
813}
814
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -0600815/**
816 * msm_ipc_router_create_server() - Add server info to hash table
817 * @service: Service ID of the server info to be created.
818 * @instance: Instance ID of the server info to be created.
819 * @node_id: Node/Processor ID in which the server is hosted.
820 * @port_id: Port ID within the node in which the server is hosted.
821 * @xprt_info: XPRT through which the node hosting the server is reached.
822 *
823 * @return: Pointer to server structure on success, else NULL.
824 *
825 * This function adds the server info to the hash table. If the same
826 * server(i.e. <service_id:instance_id>) is hosted in different nodes,
827 * they are maintained as list of "server_port" under "server" structure.
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600828 * Note: Lock the server_list_lock_lha2 before accessing this function.
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -0600829 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700830static struct msm_ipc_server *msm_ipc_router_create_server(
831 uint32_t service,
832 uint32_t instance,
833 uint32_t node_id,
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -0600834 uint32_t port_id,
835 struct msm_ipc_router_xprt_info *xprt_info)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700836{
837 struct msm_ipc_server *server = NULL;
838 struct msm_ipc_server_port *server_port;
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -0600839 int key = (service & (SRV_HASH_SIZE - 1));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700840
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700841 list_for_each_entry(server, &server_list[key], list) {
842 if ((server->name.service == service) &&
843 (server->name.instance == instance))
844 goto create_srv_port;
845 }
846
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -0600847 server = kzalloc(sizeof(struct msm_ipc_server), GFP_KERNEL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700848 if (!server) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700849 pr_err("%s: Server allocation failed\n", __func__);
850 return NULL;
851 }
852 server->name.service = service;
853 server->name.instance = instance;
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -0600854 server->synced_sec_rule = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700855 INIT_LIST_HEAD(&server->server_port_list);
856 list_add_tail(&server->list, &server_list[key]);
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -0600857 scnprintf(server->pdev_name, sizeof(server->pdev_name),
858 "QMI%08x:%08x", service, instance);
859 server->next_pdev_id = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700860
861create_srv_port:
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -0600862 server_port = kzalloc(sizeof(struct msm_ipc_server_port), GFP_KERNEL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700863 if (!server_port) {
864 if (list_empty(&server->server_port_list)) {
865 list_del(&server->list);
866 kfree(server);
867 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700868 pr_err("%s: Server Port allocation failed\n", __func__);
869 return NULL;
870 }
871 server_port->server_addr.node_id = node_id;
872 server_port->server_addr.port_id = port_id;
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -0600873 server_port->xprt_info = xprt_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874 list_add_tail(&server_port->list, &server->server_port_list);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700875
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -0600876 server_port->pdev.name = server->pdev_name;
877 server_port->pdev.id = server->next_pdev_id++;
878 server_port->pdev.dev.release = dummy_release;
879 platform_device_register(&server_port->pdev);
880
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700881 return server;
882}
883
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -0600884/**
885 * msm_ipc_router_destroy_server() - Remove server info from hash table
886 * @server: Server info to be removed.
887 * @node_id: Node/Processor ID in which the server is hosted.
888 * @port_id: Port ID within the node in which the server is hosted.
889 *
890 * This function removes the server_port identified using <node_id:port_id>
891 * from the server structure. If the server_port list under server structure
892 * is empty after removal, then remove the server structure from the server
893 * hash table.
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600894 * Note: Lock the server_list_lock_lha2 before accessing this function.
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -0600895 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700896static void msm_ipc_router_destroy_server(struct msm_ipc_server *server,
897 uint32_t node_id, uint32_t port_id)
898{
899 struct msm_ipc_server_port *server_port;
900
901 if (!server)
902 return;
903
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700904 list_for_each_entry(server_port, &server->server_port_list, list) {
905 if ((server_port->server_addr.node_id == node_id) &&
906 (server_port->server_addr.port_id == port_id))
907 break;
908 }
909 if (server_port) {
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -0600910 platform_device_unregister(&server_port->pdev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700911 list_del(&server_port->list);
912 kfree(server_port);
913 }
914 if (list_empty(&server->server_port_list)) {
915 list_del(&server->list);
916 kfree(server);
917 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700918 return;
919}
920
921static int msm_ipc_router_send_control_msg(
922 struct msm_ipc_router_xprt_info *xprt_info,
923 union rr_control_msg *msg)
924{
925 struct rr_packet *pkt;
926 struct sk_buff *ipc_rtr_pkt;
927 struct rr_header *hdr;
928 int pkt_size;
929 void *data;
930 struct sk_buff_head *pkt_fragment_q;
931 int ret;
932
933 if (!xprt_info || ((msg->cmd != IPC_ROUTER_CTRL_CMD_HELLO) &&
934 !xprt_info->initialized)) {
935 pr_err("%s: xprt_info not initialized\n", __func__);
936 return -EINVAL;
937 }
938
939 if (xprt_info->remote_node_id == IPC_ROUTER_NID_LOCAL)
940 return 0;
941
942 pkt = kzalloc(sizeof(struct rr_packet), GFP_KERNEL);
943 if (!pkt) {
944 pr_err("%s: pkt alloc failed\n", __func__);
945 return -ENOMEM;
946 }
947
948 pkt_fragment_q = kmalloc(sizeof(struct sk_buff_head), GFP_KERNEL);
949 if (!pkt_fragment_q) {
950 pr_err("%s: pkt_fragment_q alloc failed\n", __func__);
951 kfree(pkt);
952 return -ENOMEM;
953 }
954 skb_queue_head_init(pkt_fragment_q);
955
956 pkt_size = IPC_ROUTER_HDR_SIZE + sizeof(*msg);
957 ipc_rtr_pkt = alloc_skb(pkt_size, GFP_KERNEL);
958 if (!ipc_rtr_pkt) {
959 pr_err("%s: ipc_rtr_pkt alloc failed\n", __func__);
960 kfree(pkt_fragment_q);
961 kfree(pkt);
962 return -ENOMEM;
963 }
964
965 skb_reserve(ipc_rtr_pkt, IPC_ROUTER_HDR_SIZE);
966 data = skb_put(ipc_rtr_pkt, sizeof(*msg));
967 memcpy(data, msg, sizeof(*msg));
968 hdr = (struct rr_header *)skb_push(ipc_rtr_pkt, IPC_ROUTER_HDR_SIZE);
969 if (!hdr) {
970 pr_err("%s: skb_push failed\n", __func__);
971 kfree_skb(ipc_rtr_pkt);
972 kfree(pkt_fragment_q);
973 kfree(pkt);
974 return -ENOMEM;
975 }
976
977 hdr->version = IPC_ROUTER_VERSION;
978 hdr->type = msg->cmd;
979 hdr->src_node_id = IPC_ROUTER_NID_LOCAL;
980 hdr->src_port_id = IPC_ROUTER_ADDRESS;
981 hdr->confirm_rx = 0;
982 hdr->size = sizeof(*msg);
983 hdr->dst_node_id = xprt_info->remote_node_id;
984 hdr->dst_port_id = IPC_ROUTER_ADDRESS;
985 skb_queue_tail(pkt_fragment_q, ipc_rtr_pkt);
986 pkt->pkt_fragment_q = pkt_fragment_q;
987 pkt->length = pkt_size;
988
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600989 mutex_lock(&xprt_info->tx_lock_lhb2);
Karthikeyan Ramasubramanian8cec5922012-02-16 17:41:58 -0700990 ret = xprt_info->xprt->write(pkt, pkt_size, xprt_info->xprt);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -0600991 mutex_unlock(&xprt_info->tx_lock_lhb2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700992
993 release_pkt(pkt);
994 return ret;
995}
996
Karthikeyan Ramasubramanianb234c242012-10-23 13:12:44 -0600997static int msm_ipc_router_send_server_list(uint32_t node_id,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700998 struct msm_ipc_router_xprt_info *xprt_info)
999{
1000 union rr_control_msg ctl;
1001 struct msm_ipc_server *server;
1002 struct msm_ipc_server_port *server_port;
1003 int i;
1004
1005 if (!xprt_info || !xprt_info->initialized) {
1006 pr_err("%s: Xprt info not initialized\n", __func__);
1007 return -EINVAL;
1008 }
1009
1010 ctl.cmd = IPC_ROUTER_CTRL_CMD_NEW_SERVER;
1011
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001012 for (i = 0; i < SRV_HASH_SIZE; i++) {
1013 list_for_each_entry(server, &server_list[i], list) {
1014 ctl.srv.service = server->name.service;
1015 ctl.srv.instance = server->name.instance;
1016 list_for_each_entry(server_port,
1017 &server->server_port_list, list) {
Karthikeyan Ramasubramanianb234c242012-10-23 13:12:44 -06001018 if (server_port->server_addr.node_id !=
1019 node_id)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001020 continue;
1021
1022 ctl.srv.node_id =
1023 server_port->server_addr.node_id;
1024 ctl.srv.port_id =
1025 server_port->server_addr.port_id;
1026 msm_ipc_router_send_control_msg(xprt_info,
1027 &ctl);
1028 }
1029 }
1030 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001031
1032 return 0;
1033}
1034
1035#if defined(DEBUG)
1036static char *type_to_str(int i)
1037{
1038 switch (i) {
1039 case IPC_ROUTER_CTRL_CMD_DATA:
1040 return "data ";
1041 case IPC_ROUTER_CTRL_CMD_HELLO:
1042 return "hello ";
1043 case IPC_ROUTER_CTRL_CMD_BYE:
1044 return "bye ";
1045 case IPC_ROUTER_CTRL_CMD_NEW_SERVER:
1046 return "new_srvr";
1047 case IPC_ROUTER_CTRL_CMD_REMOVE_SERVER:
1048 return "rmv_srvr";
1049 case IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT:
1050 return "rmv_clnt";
1051 case IPC_ROUTER_CTRL_CMD_RESUME_TX:
1052 return "resum_tx";
1053 case IPC_ROUTER_CTRL_CMD_EXIT:
1054 return "cmd_exit";
1055 default:
1056 return "invalid";
1057 }
1058}
1059#endif
1060
1061static int broadcast_ctl_msg_locally(union rr_control_msg *msg)
1062{
1063 struct rr_packet *pkt;
1064 struct sk_buff *ipc_rtr_pkt;
1065 struct rr_header *hdr;
1066 int pkt_size;
1067 void *data;
1068 struct sk_buff_head *pkt_fragment_q;
1069 int ret;
1070
1071 pkt = kzalloc(sizeof(struct rr_packet), GFP_KERNEL);
1072 if (!pkt) {
1073 pr_err("%s: pkt alloc failed\n", __func__);
1074 return -ENOMEM;
1075 }
1076
1077 pkt_fragment_q = kmalloc(sizeof(struct sk_buff_head), GFP_KERNEL);
1078 if (!pkt_fragment_q) {
1079 pr_err("%s: pkt_fragment_q alloc failed\n", __func__);
1080 kfree(pkt);
1081 return -ENOMEM;
1082 }
1083 skb_queue_head_init(pkt_fragment_q);
1084
1085 pkt_size = IPC_ROUTER_HDR_SIZE + sizeof(*msg);
1086 ipc_rtr_pkt = alloc_skb(pkt_size, GFP_KERNEL);
1087 if (!ipc_rtr_pkt) {
1088 pr_err("%s: ipc_rtr_pkt alloc failed\n", __func__);
1089 kfree(pkt_fragment_q);
1090 kfree(pkt);
1091 return -ENOMEM;
1092 }
1093
1094 skb_reserve(ipc_rtr_pkt, IPC_ROUTER_HDR_SIZE);
1095 data = skb_put(ipc_rtr_pkt, sizeof(*msg));
1096 memcpy(data, msg, sizeof(*msg));
1097 hdr = (struct rr_header *)skb_push(ipc_rtr_pkt, IPC_ROUTER_HDR_SIZE);
1098 if (!hdr) {
1099 pr_err("%s: skb_push failed\n", __func__);
1100 kfree_skb(ipc_rtr_pkt);
1101 kfree(pkt_fragment_q);
1102 kfree(pkt);
1103 return -ENOMEM;
1104 }
1105 hdr->version = IPC_ROUTER_VERSION;
1106 hdr->type = msg->cmd;
1107 hdr->src_node_id = IPC_ROUTER_NID_LOCAL;
1108 hdr->src_port_id = IPC_ROUTER_ADDRESS;
1109 hdr->confirm_rx = 0;
1110 hdr->size = sizeof(*msg);
1111 hdr->dst_node_id = IPC_ROUTER_NID_LOCAL;
1112 hdr->dst_port_id = IPC_ROUTER_ADDRESS;
1113 skb_queue_tail(pkt_fragment_q, ipc_rtr_pkt);
1114 pkt->pkt_fragment_q = pkt_fragment_q;
1115 pkt->length = pkt_size;
1116
1117 ret = post_control_ports(pkt);
1118 release_pkt(pkt);
1119 return ret;
1120}
1121
1122static int broadcast_ctl_msg(union rr_control_msg *ctl)
1123{
1124 struct msm_ipc_router_xprt_info *xprt_info;
1125
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001126 down_read(&xprt_info_list_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001127 list_for_each_entry(xprt_info, &xprt_info_list, list) {
1128 msm_ipc_router_send_control_msg(xprt_info, ctl);
1129 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001130 up_read(&xprt_info_list_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001131
1132 return 0;
1133}
1134
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001135static int relay_ctl_msg(struct msm_ipc_router_xprt_info *xprt_info,
1136 union rr_control_msg *ctl)
1137{
1138 struct msm_ipc_router_xprt_info *fwd_xprt_info;
1139
1140 if (!xprt_info || !ctl)
1141 return -EINVAL;
1142
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001143 down_read(&xprt_info_list_lock_lha5);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001144 list_for_each_entry(fwd_xprt_info, &xprt_info_list, list) {
1145 if (xprt_info->xprt->link_id != fwd_xprt_info->xprt->link_id)
1146 msm_ipc_router_send_control_msg(fwd_xprt_info, ctl);
1147 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001148 up_read(&xprt_info_list_lock_lha5);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001149
1150 return 0;
1151}
1152
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001153static int relay_msg(struct msm_ipc_router_xprt_info *xprt_info,
1154 struct rr_packet *pkt)
1155{
1156 struct msm_ipc_router_xprt_info *fwd_xprt_info;
1157
1158 if (!xprt_info || !pkt)
1159 return -EINVAL;
1160
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001161 down_read(&xprt_info_list_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001162 list_for_each_entry(fwd_xprt_info, &xprt_info_list, list) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001163 mutex_lock(&fwd_xprt_info->tx_lock_lhb2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001164 if (xprt_info->xprt->link_id != fwd_xprt_info->xprt->link_id)
Karthikeyan Ramasubramanian8cec5922012-02-16 17:41:58 -07001165 fwd_xprt_info->xprt->write(pkt, pkt->length,
1166 fwd_xprt_info->xprt);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001167 mutex_unlock(&fwd_xprt_info->tx_lock_lhb2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001168 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001169 up_read(&xprt_info_list_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001170 return 0;
1171}
1172
1173static int forward_msg(struct msm_ipc_router_xprt_info *xprt_info,
1174 struct rr_packet *pkt)
1175{
1176 uint32_t dst_node_id;
1177 struct sk_buff *head_pkt;
1178 struct rr_header *hdr;
1179 struct msm_ipc_router_xprt_info *fwd_xprt_info;
1180 struct msm_ipc_routing_table_entry *rt_entry;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001181 int ret = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001182
1183 if (!xprt_info || !pkt)
1184 return -EINVAL;
1185
1186 head_pkt = skb_peek(pkt->pkt_fragment_q);
1187 if (!head_pkt)
1188 return -EINVAL;
1189
1190 hdr = (struct rr_header *)head_pkt->data;
1191 dst_node_id = hdr->dst_node_id;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001192 down_read(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001193 rt_entry = lookup_routing_table(dst_node_id);
1194 if (!(rt_entry) || !(rt_entry->xprt_info)) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001195 up_read(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001196 pr_err("%s: Routing table not initialized\n", __func__);
1197 return -ENODEV;
1198 }
1199
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001200 down_read(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001201 fwd_xprt_info = rt_entry->xprt_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001202 if (xprt_info->remote_node_id == fwd_xprt_info->remote_node_id) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001203 pr_err("%s: Discarding Command to route back\n", __func__);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001204 ret = -EINVAL;
1205 goto fwd_msg_out;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001206 }
1207
1208 if (xprt_info->xprt->link_id == fwd_xprt_info->xprt->link_id) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001209 pr_err("%s: DST in the same cluster\n", __func__);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001210 goto fwd_msg_out;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001211 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001212 mutex_lock(&fwd_xprt_info->tx_lock_lhb2);
Karthikeyan Ramasubramanian8cec5922012-02-16 17:41:58 -07001213 fwd_xprt_info->xprt->write(pkt, pkt->length, fwd_xprt_info->xprt);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001214 mutex_unlock(&fwd_xprt_info->tx_lock_lhb2);
1215fwd_msg_out:
1216 up_read(&rt_entry->lock_lha4);
1217 up_read(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001218
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001219 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001220}
1221
Karthikeyan Ramasubramaniandc9c4442013-05-02 17:25:54 -06001222static int msm_ipc_router_send_remove_client(struct comm_mode_info *mode_info,
1223 uint32_t node_id, uint32_t port_id)
1224{
1225 union rr_control_msg msg;
1226 struct msm_ipc_router_xprt_info *tmp_xprt_info;
1227 int mode;
1228 void *xprt_info;
1229 int rc = 0;
1230
1231 if (!mode_info) {
1232 pr_err("%s: NULL mode_info\n", __func__);
1233 return -EINVAL;
1234 }
1235 mode = mode_info->mode;
1236 xprt_info = mode_info->xprt_info;
1237
1238 msg.cmd = IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT;
1239 msg.cli.node_id = node_id;
1240 msg.cli.port_id = port_id;
1241
1242 if ((mode == SINGLE_LINK_MODE) && xprt_info) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001243 down_read(&xprt_info_list_lock_lha5);
Karthikeyan Ramasubramaniandc9c4442013-05-02 17:25:54 -06001244 list_for_each_entry(tmp_xprt_info, &xprt_info_list, list) {
1245 if (tmp_xprt_info != xprt_info)
1246 continue;
1247 msm_ipc_router_send_control_msg(tmp_xprt_info, &msg);
1248 break;
1249 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001250 up_read(&xprt_info_list_lock_lha5);
Karthikeyan Ramasubramaniandc9c4442013-05-02 17:25:54 -06001251 } else if ((mode == SINGLE_LINK_MODE) && !xprt_info) {
1252 broadcast_ctl_msg_locally(&msg);
1253 } else if (mode == MULTI_LINK_MODE) {
1254 broadcast_ctl_msg(&msg);
1255 broadcast_ctl_msg_locally(&msg);
1256 } else if (mode != NULL_MODE) {
1257 pr_err("%s: Invalid mode(%d) + xprt_inf(%p) for %08x:%08x\n",
1258 __func__, mode, xprt_info, node_id, port_id);
1259 rc = -EINVAL;
1260 }
1261 return rc;
1262}
1263
1264static void update_comm_mode_info(struct comm_mode_info *mode_info,
1265 struct msm_ipc_router_xprt_info *xprt_info)
1266{
1267 if (!mode_info) {
1268 pr_err("%s: NULL mode_info\n", __func__);
1269 return;
1270 }
1271
1272 if (mode_info->mode == NULL_MODE) {
1273 mode_info->xprt_info = xprt_info;
1274 mode_info->mode = SINGLE_LINK_MODE;
1275 } else if (mode_info->mode == SINGLE_LINK_MODE &&
1276 mode_info->xprt_info != xprt_info) {
1277 mode_info->mode = MULTI_LINK_MODE;
1278 }
1279
1280 return;
1281}
1282
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001283static void cleanup_rmt_server(struct msm_ipc_router_xprt_info *xprt_info,
1284 struct msm_ipc_router_remote_port *rport_ptr)
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001285{
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001286 union rr_control_msg ctl;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001287 struct msm_ipc_server *server = rport_ptr->server;
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001288
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001289 D("Remove server %08x:%08x - %08x:%08x",
1290 server->name.service, server->name.instance,
1291 rport_ptr->node_id, rport_ptr->port_id);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001292 ctl.cmd = IPC_ROUTER_CTRL_CMD_REMOVE_SERVER;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001293 ctl.srv.service = server->name.service;
1294 ctl.srv.instance = server->name.instance;
1295 ctl.srv.node_id = rport_ptr->node_id;
1296 ctl.srv.port_id = rport_ptr->port_id;
1297 relay_ctl_msg(xprt_info, &ctl);
1298 broadcast_ctl_msg_locally(&ctl);
1299 msm_ipc_router_destroy_server(server,
1300 rport_ptr->node_id, rport_ptr->port_id);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001301}
1302
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001303static void cleanup_rmt_ports(struct msm_ipc_router_xprt_info *xprt_info,
1304 struct msm_ipc_routing_table_entry *rt_entry)
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001305{
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001306 struct msm_ipc_router_remote_port *rport_ptr, *tmp_rport_ptr;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001307 union rr_control_msg ctl;
1308 int j;
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001309
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001310 for (j = 0; j < RP_HASH_SIZE; j++) {
1311 list_for_each_entry_safe(rport_ptr, tmp_rport_ptr,
1312 &rt_entry->remote_port_list[j], list) {
1313 list_del(&rport_ptr->list);
1314 mutex_lock(&rport_ptr->quota_lock_lhb2);
1315 msm_ipc_router_free_resume_tx_port(rport_ptr);
1316 mutex_unlock(&rport_ptr->quota_lock_lhb2);
1317
1318 if (rport_ptr->server)
1319 cleanup_rmt_server(xprt_info, rport_ptr);
1320
1321 ctl.cmd = IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT;
1322 ctl.cli.node_id = rport_ptr->node_id;
1323 ctl.cli.port_id = rport_ptr->port_id;
1324 relay_ctl_msg(xprt_info, &ctl);
1325 broadcast_ctl_msg_locally(&ctl);
1326 kfree(rport_ptr);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001327 }
1328 }
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001329}
1330
1331static void msm_ipc_cleanup_routing_table(
1332 struct msm_ipc_router_xprt_info *xprt_info)
1333{
1334 int i;
1335 struct msm_ipc_routing_table_entry *rt_entry;
1336
1337 if (!xprt_info) {
1338 pr_err("%s: Invalid xprt_info\n", __func__);
1339 return;
1340 }
1341
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001342 down_write(&server_list_lock_lha2);
1343 down_write(&routing_table_lock_lha3);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001344 for (i = 0; i < RT_HASH_SIZE; i++) {
1345 list_for_each_entry(rt_entry, &routing_table[i], list) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001346 down_write(&rt_entry->lock_lha4);
1347 if (rt_entry->xprt_info != xprt_info) {
1348 up_write(&rt_entry->lock_lha4);
1349 continue;
1350 }
1351 cleanup_rmt_ports(xprt_info, rt_entry);
1352 rt_entry->xprt_info = NULL;
1353 up_write(&rt_entry->lock_lha4);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001354 }
1355 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001356 up_write(&routing_table_lock_lha3);
1357 up_write(&server_list_lock_lha2);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001358}
1359
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -06001360/**
1361 * sync_sec_rule() - Synchrnoize the security rule into the server structure
1362 * @server: Server structure where the rule has to be synchronized.
1363 * @rule: Security tule to be synchronized.
1364 *
1365 * This function is used to update the server structure with the security
1366 * rule configured for the <service:instance> corresponding to that server.
1367 */
1368static void sync_sec_rule(struct msm_ipc_server *server, void *rule)
1369{
1370 struct msm_ipc_server_port *server_port;
1371 struct msm_ipc_router_remote_port *rport_ptr = NULL;
1372
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001373 down_read(&routing_table_lock_lha3);
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -06001374 list_for_each_entry(server_port, &server->server_port_list, list) {
1375 rport_ptr = msm_ipc_router_lookup_remote_port(
1376 server_port->server_addr.node_id,
1377 server_port->server_addr.port_id);
1378 if (!rport_ptr)
1379 continue;
1380 rport_ptr->sec_rule = rule;
1381 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001382 up_read(&routing_table_lock_lha3);
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -06001383 server->synced_sec_rule = 1;
1384}
1385
1386/**
1387 * msm_ipc_sync_sec_rule() - Sync the security rule to the service
1388 * @service: Service for which the rule has to be synchronized.
1389 * @instance: Instance for which the rule has to be synchronized.
1390 * @rule: Security rule to be synchronized.
1391 *
1392 * This function is used to syncrhonize the security rule with the server
1393 * hash table, if the user-space script configures the rule after the service
1394 * has come up. This function is used to synchronize the security rule to a
1395 * specific service and optionally a specific instance.
1396 */
1397void msm_ipc_sync_sec_rule(uint32_t service, uint32_t instance, void *rule)
1398{
1399 int key = (service & (SRV_HASH_SIZE - 1));
1400 struct msm_ipc_server *server;
1401
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001402 down_write(&server_list_lock_lha2);
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -06001403 list_for_each_entry(server, &server_list[key], list) {
1404 if (server->name.service != service)
1405 continue;
1406
1407 if (server->name.instance != instance &&
1408 instance != ALL_INSTANCE)
1409 continue;
1410
1411 /*
1412 * If the rule applies to all instances and if the specific
1413 * instance of a service has a rule synchronized already,
1414 * do not apply the rule for that specific instance.
1415 */
1416 if (instance == ALL_INSTANCE && server->synced_sec_rule)
1417 continue;
1418
1419 sync_sec_rule(server, rule);
1420 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001421 up_write(&server_list_lock_lha2);
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -06001422}
1423
1424/**
1425 * msm_ipc_sync_default_sec_rule() - Default security rule to all services
1426 * @rule: Security rule to be synchronized.
1427 *
1428 * This function is used to syncrhonize the security rule with the server
1429 * hash table, if the user-space script configures the rule after the service
1430 * has come up. This function is used to synchronize the security rule that
1431 * applies to all services, if the concerned service do not have any rule
1432 * defined.
1433 */
1434void msm_ipc_sync_default_sec_rule(void *rule)
1435{
1436 int key;
1437 struct msm_ipc_server *server;
1438
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001439 down_write(&server_list_lock_lha2);
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -06001440 for (key = 0; key < SRV_HASH_SIZE; key++) {
1441 list_for_each_entry(server, &server_list[key], list) {
1442 if (server->synced_sec_rule)
1443 continue;
1444
1445 sync_sec_rule(server, rule);
1446 }
1447 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001448 up_write(&server_list_lock_lha2);
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -06001449}
1450
Karthikeyan Ramasubramanianb234c242012-10-23 13:12:44 -06001451static int process_hello_msg(struct msm_ipc_router_xprt_info *xprt_info,
1452 struct rr_header *hdr)
1453{
1454 int i, rc = 0;
1455 union rr_control_msg ctl;
1456 struct msm_ipc_routing_table_entry *rt_entry;
1457
1458 if (!hdr)
1459 return -EINVAL;
1460
1461 RR("o HELLO NID %d\n", hdr->src_node_id);
1462
1463 xprt_info->remote_node_id = hdr->src_node_id;
1464 /*
1465 * Find the entry from Routing Table corresponding to Node ID.
1466 * Under SSR, an entry will be found. When the system boots up
1467 * for the 1st time, an entry will not be found and hence allocate
1468 * an entry. Update the entry with the Node ID that it corresponds
1469 * to and the XPRT through which it can be reached.
1470 */
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001471 down_write(&routing_table_lock_lha3);
Karthikeyan Ramasubramanianb234c242012-10-23 13:12:44 -06001472 rt_entry = lookup_routing_table(hdr->src_node_id);
1473 if (!rt_entry) {
1474 rt_entry = alloc_routing_table_entry(hdr->src_node_id);
1475 if (!rt_entry) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001476 up_write(&routing_table_lock_lha3);
Karthikeyan Ramasubramanianb234c242012-10-23 13:12:44 -06001477 pr_err("%s: rt_entry allocation failed\n", __func__);
1478 return -ENOMEM;
1479 }
1480 add_routing_table_entry(rt_entry);
1481 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001482 down_write(&rt_entry->lock_lha4);
Karthikeyan Ramasubramanianb234c242012-10-23 13:12:44 -06001483 rt_entry->neighbor_node_id = xprt_info->remote_node_id;
1484 rt_entry->xprt_info = xprt_info;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001485 up_write(&rt_entry->lock_lha4);
1486 up_write(&routing_table_lock_lha3);
Karthikeyan Ramasubramanianb234c242012-10-23 13:12:44 -06001487
1488 /* Send a reply HELLO message */
1489 memset(&ctl, 0, sizeof(ctl));
1490 ctl.cmd = IPC_ROUTER_CTRL_CMD_HELLO;
1491 rc = msm_ipc_router_send_control_msg(xprt_info, &ctl);
1492 if (rc < 0) {
1493 pr_err("%s: Error sending reply HELLO message\n", __func__);
1494 return rc;
1495 }
1496 xprt_info->initialized = 1;
1497
1498 /*
1499 * Send list of servers from the local node and from nodes
1500 * outside the mesh network in which this XPRT is part of.
1501 */
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001502 down_read(&server_list_lock_lha2);
1503 down_read(&routing_table_lock_lha3);
Karthikeyan Ramasubramanianb234c242012-10-23 13:12:44 -06001504 for (i = 0; i < RT_HASH_SIZE; i++) {
1505 list_for_each_entry(rt_entry, &routing_table[i], list) {
1506 if ((rt_entry->node_id != IPC_ROUTER_NID_LOCAL) &&
Karthikeyan Ramasubramanian72ad5792013-01-30 14:17:57 -07001507 (!rt_entry->xprt_info ||
1508 (rt_entry->xprt_info->xprt->link_id ==
1509 xprt_info->xprt->link_id)))
Karthikeyan Ramasubramanianb234c242012-10-23 13:12:44 -06001510 continue;
1511 rc = msm_ipc_router_send_server_list(rt_entry->node_id,
1512 xprt_info);
1513 if (rc < 0) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001514 up_read(&routing_table_lock_lha3);
1515 up_read(&server_list_lock_lha2);
Karthikeyan Ramasubramanianb234c242012-10-23 13:12:44 -06001516 return rc;
1517 }
1518 }
1519 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001520 up_read(&routing_table_lock_lha3);
1521 up_read(&server_list_lock_lha2);
Karthikeyan Ramasubramanianb234c242012-10-23 13:12:44 -06001522 RR("HELLO message processed\n");
1523 return rc;
1524}
1525
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001526static int process_resume_tx_msg(union rr_control_msg *msg,
1527 struct rr_packet *pkt)
1528{
1529 struct msm_ipc_router_remote_port *rport_ptr;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001530 int ret = 0;
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001531
1532 RR("o RESUME_TX id=%d:%08x\n", msg->cli.node_id, msg->cli.port_id);
1533
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001534 down_read(&local_ports_lock_lha2);
1535 down_read(&routing_table_lock_lha3);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001536 rport_ptr = msm_ipc_router_lookup_remote_port(msg->cli.node_id,
1537 msg->cli.port_id);
1538 if (!rport_ptr) {
1539 pr_err("%s: Unable to resume client\n", __func__);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001540 ret = -ENODEV;
1541 goto prtm_out;
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001542 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001543 mutex_lock(&rport_ptr->quota_lock_lhb2);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001544 rport_ptr->tx_quota_cnt = 0;
1545 post_resume_tx(rport_ptr, pkt);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001546 mutex_unlock(&rport_ptr->quota_lock_lhb2);
1547prtm_out:
1548 up_read(&routing_table_lock_lha3);
1549 up_read(&local_ports_lock_lha2);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001550 return 0;
1551}
1552
1553static int process_new_server_msg(struct msm_ipc_router_xprt_info *xprt_info,
1554 union rr_control_msg *msg, struct rr_packet *pkt)
1555{
1556 struct msm_ipc_routing_table_entry *rt_entry;
1557 struct msm_ipc_server *server;
1558 struct msm_ipc_router_remote_port *rport_ptr;
1559
1560 if (msg->srv.instance == 0) {
1561 pr_err("%s: Server %08x create rejected, version = 0\n",
1562 __func__, msg->srv.service);
1563 return -EINVAL;
1564 }
1565
1566 RR("o NEW_SERVER id=%d:%08x service=%08x:%08x\n", msg->srv.node_id,
1567 msg->srv.port_id, msg->srv.service, msg->srv.instance);
1568 /*
1569 * Find the entry from Routing Table corresponding to Node ID.
1570 * Under SSR, an entry will be found. When the subsystem hosting
1571 * service is not adjacent, an entry will not be found and hence
1572 * allocate an entry. Update the entry with the Node ID that it
1573 * corresponds to and the XPRT through which it can be reached.
1574 */
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001575 down_write(&routing_table_lock_lha3);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001576 rt_entry = lookup_routing_table(msg->srv.node_id);
1577 if (!rt_entry) {
1578 rt_entry = alloc_routing_table_entry(msg->srv.node_id);
1579 if (!rt_entry) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001580 up_write(&routing_table_lock_lha3);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001581 pr_err("%s: rt_entry allocation failed\n", __func__);
1582 return -ENOMEM;
1583 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001584 down_write(&rt_entry->lock_lha4);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001585 rt_entry->neighbor_node_id = xprt_info->remote_node_id;
1586 rt_entry->xprt_info = xprt_info;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001587 up_write(&rt_entry->lock_lha4);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001588 add_routing_table_entry(rt_entry);
1589 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001590 up_write(&routing_table_lock_lha3);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001591
1592 /*
1593 * If the service does not exist already in the database, create and
1594 * store the service info. Create a remote port structure in which
1595 * the service is hosted and cache the security rule for the service
1596 * in that remote port structure.
1597 */
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001598 down_write(&server_list_lock_lha2);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001599 server = msm_ipc_router_lookup_server(msg->srv.service,
1600 msg->srv.instance, msg->srv.node_id, msg->srv.port_id);
1601 if (!server) {
1602 server = msm_ipc_router_create_server(
1603 msg->srv.service, msg->srv.instance,
1604 msg->srv.node_id, msg->srv.port_id, xprt_info);
1605 if (!server) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001606 up_write(&server_list_lock_lha2);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001607 pr_err("%s: Server Create failed\n", __func__);
1608 return -ENOMEM;
1609 }
1610
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001611 down_read(&routing_table_lock_lha3);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001612 if (!msm_ipc_router_lookup_remote_port(
1613 msg->srv.node_id, msg->srv.port_id)) {
1614 rport_ptr = msm_ipc_router_create_remote_port(
1615 msg->srv.node_id, msg->srv.port_id);
1616 if (!rport_ptr) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001617 up_read(&routing_table_lock_lha3);
1618 up_write(&server_list_lock_lha2);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001619 return -ENOMEM;
1620 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001621 rport_ptr->server = server;
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001622 rport_ptr->sec_rule = msm_ipc_get_security_rule(
1623 msg->srv.service,
1624 msg->srv.instance);
1625 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001626 up_read(&routing_table_lock_lha3);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001627 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001628 up_write(&server_list_lock_lha2);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001629
1630 /*
1631 * Relay the new server message to other subsystems that do not belong
1632 * to the cluster from which this message is received. Notify the
1633 * local clients waiting for this service.
1634 */
1635 relay_msg(xprt_info, pkt);
1636 post_control_ports(pkt);
1637 return 0;
1638}
1639
1640static int process_rmv_server_msg(struct msm_ipc_router_xprt_info *xprt_info,
1641 union rr_control_msg *msg, struct rr_packet *pkt)
1642{
1643 struct msm_ipc_server *server;
1644
1645 RR("o REMOVE_SERVER service=%08x:%d\n",
1646 msg->srv.service, msg->srv.instance);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001647 down_write(&server_list_lock_lha2);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001648 server = msm_ipc_router_lookup_server(msg->srv.service,
1649 msg->srv.instance, msg->srv.node_id, msg->srv.port_id);
1650 if (server) {
1651 msm_ipc_router_destroy_server(server, msg->srv.node_id,
1652 msg->srv.port_id);
1653 /*
1654 * Relay the new server message to other subsystems that do not
1655 * belong to the cluster from which this message is received.
1656 * Notify the local clients communicating with the service.
1657 */
1658 relay_msg(xprt_info, pkt);
1659 post_control_ports(pkt);
1660 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001661 up_write(&server_list_lock_lha2);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001662 return 0;
1663}
1664
1665static int process_rmv_client_msg(struct msm_ipc_router_xprt_info *xprt_info,
1666 union rr_control_msg *msg, struct rr_packet *pkt)
1667{
1668 struct msm_ipc_router_remote_port *rport_ptr;
1669
1670 RR("o REMOVE_CLIENT id=%d:%08x\n", msg->cli.node_id, msg->cli.port_id);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001671 down_write(&routing_table_lock_lha3);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001672 rport_ptr = msm_ipc_router_lookup_remote_port(msg->cli.node_id,
1673 msg->cli.port_id);
1674 if (rport_ptr)
1675 msm_ipc_router_destroy_remote_port(rport_ptr);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001676 up_write(&routing_table_lock_lha3);
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001677
1678 relay_msg(xprt_info, pkt);
1679 post_control_ports(pkt);
1680 return 0;
1681}
1682
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001683static int process_control_msg(struct msm_ipc_router_xprt_info *xprt_info,
1684 struct rr_packet *pkt)
1685{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001686 union rr_control_msg *msg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001687 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001688 struct sk_buff *temp_ptr;
1689 struct rr_header *hdr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001690
1691 if (pkt->length != (IPC_ROUTER_HDR_SIZE + sizeof(*msg))) {
1692 pr_err("%s: r2r msg size %d != %d\n", __func__, pkt->length,
1693 (IPC_ROUTER_HDR_SIZE + sizeof(*msg)));
1694 return -EINVAL;
1695 }
1696
1697 temp_ptr = skb_peek(pkt->pkt_fragment_q);
Karthikeyan Ramasubramanian9024dd82011-12-19 18:44:19 -07001698 if (!temp_ptr) {
1699 pr_err("%s: pkt_fragment_q is empty\n", __func__);
1700 return -EINVAL;
1701 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001702 hdr = (struct rr_header *)temp_ptr->data;
Karthikeyan Ramasubramanian9024dd82011-12-19 18:44:19 -07001703 if (!hdr) {
1704 pr_err("%s: No data inside the skb\n", __func__);
1705 return -EINVAL;
1706 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001707 msg = (union rr_control_msg *)((char *)hdr + IPC_ROUTER_HDR_SIZE);
1708
1709 switch (msg->cmd) {
1710 case IPC_ROUTER_CTRL_CMD_HELLO:
Karthikeyan Ramasubramanianb234c242012-10-23 13:12:44 -06001711 rc = process_hello_msg(xprt_info, hdr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001712 break;
1713 case IPC_ROUTER_CTRL_CMD_RESUME_TX:
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001714 rc = process_resume_tx_msg(msg, pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001715 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001716 case IPC_ROUTER_CTRL_CMD_NEW_SERVER:
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001717 rc = process_new_server_msg(xprt_info, msg, pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001718 break;
1719 case IPC_ROUTER_CTRL_CMD_REMOVE_SERVER:
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001720 rc = process_rmv_server_msg(xprt_info, msg, pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001721 break;
1722 case IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT:
Karthikeyan Ramasubramanian4b4120e2013-05-17 18:18:20 -06001723 rc = process_rmv_client_msg(xprt_info, msg, pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001724 break;
1725 case IPC_ROUTER_CTRL_CMD_PING:
1726 /* No action needed for ping messages received */
1727 RR("o PING\n");
1728 break;
1729 default:
1730 RR("o UNKNOWN(%08x)\n", msg->cmd);
1731 rc = -ENOSYS;
1732 }
1733
1734 return rc;
1735}
1736
1737static void do_read_data(struct work_struct *work)
1738{
1739 struct rr_header *hdr;
1740 struct rr_packet *pkt = NULL;
1741 struct msm_ipc_port *port_ptr;
1742 struct sk_buff *head_skb;
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001743 struct msm_ipc_router_remote_port *rport_ptr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001744 uint32_t resume_tx, resume_tx_node_id, resume_tx_port_id;
1745
1746 struct msm_ipc_router_xprt_info *xprt_info =
1747 container_of(work,
1748 struct msm_ipc_router_xprt_info,
1749 read_data);
1750
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001751 while ((pkt = rr_read(xprt_info)) != NULL) {
1752 if (pkt->length < IPC_ROUTER_HDR_SIZE ||
1753 pkt->length > MAX_IPC_PKT_SIZE) {
1754 pr_err("%s: Invalid pkt length %d\n",
1755 __func__, pkt->length);
1756 goto fail_data;
1757 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001758
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001759 head_skb = skb_peek(pkt->pkt_fragment_q);
1760 if (!head_skb) {
1761 pr_err("%s: head_skb is invalid\n", __func__);
1762 goto fail_data;
1763 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001764
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001765 hdr = (struct rr_header *)(head_skb->data);
Karthikeyan Ramasubramanian682ebcc2013-03-22 10:47:20 -06001766 RAW("ver=%d type=%d src=%d:%08x crx=%d siz=%d dst=%d:%08x\n",
1767 hdr->version, hdr->type, hdr->src_node_id,
1768 hdr->src_port_id, hdr->confirm_rx, hdr->size,
1769 hdr->dst_node_id, hdr->dst_port_id);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001770
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001771 if (hdr->version != IPC_ROUTER_VERSION) {
1772 pr_err("version %d != %d\n",
1773 hdr->version, IPC_ROUTER_VERSION);
1774 goto fail_data;
1775 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001776
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001777 if ((hdr->dst_node_id != IPC_ROUTER_NID_LOCAL) &&
1778 ((hdr->type == IPC_ROUTER_CTRL_CMD_RESUME_TX) ||
1779 (hdr->type == IPC_ROUTER_CTRL_CMD_DATA))) {
1780 forward_msg(xprt_info, pkt);
1781 release_pkt(pkt);
1782 continue;
1783 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001784
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001785 if ((hdr->dst_port_id == IPC_ROUTER_ADDRESS) ||
1786 (hdr->type == IPC_ROUTER_CTRL_CMD_HELLO)) {
1787 process_control_msg(xprt_info, pkt);
1788 release_pkt(pkt);
1789 continue;
1790 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001791#if defined(CONFIG_MSM_SMD_LOGGING)
1792#if defined(DEBUG)
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001793 if (msm_ipc_router_debug_mask & SMEM_LOG) {
1794 smem_log_event((SMEM_LOG_PROC_ID_APPS |
1795 SMEM_LOG_RPC_ROUTER_EVENT_BASE |
1796 IPC_ROUTER_LOG_EVENT_RX),
1797 (hdr->src_node_id << 24) |
1798 (hdr->src_port_id & 0xffffff),
1799 (hdr->dst_node_id << 24) |
1800 (hdr->dst_port_id & 0xffffff),
1801 (hdr->type << 24) | (hdr->confirm_rx << 16) |
1802 (hdr->size & 0xffff));
1803 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001804#endif
1805#endif
1806
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001807 resume_tx = hdr->confirm_rx;
1808 resume_tx_node_id = hdr->dst_node_id;
1809 resume_tx_port_id = hdr->dst_port_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001810
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001811 down_read(&local_ports_lock_lha2);
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001812 port_ptr = msm_ipc_router_lookup_local_port(hdr->dst_port_id);
1813 if (!port_ptr) {
1814 pr_err("%s: No local port id %08x\n", __func__,
1815 hdr->dst_port_id);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001816 up_read(&local_ports_lock_lha2);
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001817 release_pkt(pkt);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001818 goto process_done;
1819 }
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001820
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001821 down_read(&routing_table_lock_lha3);
1822 rport_ptr = msm_ipc_router_lookup_remote_port(hdr->src_node_id,
1823 hdr->src_port_id);
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001824 if (!rport_ptr) {
1825 rport_ptr = msm_ipc_router_create_remote_port(
1826 hdr->src_node_id,
1827 hdr->src_port_id);
1828 if (!rport_ptr) {
1829 pr_err("%s: Rmt Prt %08x:%08x create failed\n",
1830 __func__, hdr->src_node_id,
1831 hdr->src_port_id);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001832 up_read(&routing_table_lock_lha3);
1833 up_read(&local_ports_lock_lha2);
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001834 goto process_done;
1835 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001836 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001837 up_read(&routing_table_lock_lha3);
Karthikeyan Ramasubramaniand1af6252013-05-17 15:19:56 -06001838 post_pkt_to_port(port_ptr, pkt, 0);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001839 up_read(&local_ports_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001840
1841process_done:
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001842 if (resume_tx) {
1843 union rr_control_msg msg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001844
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001845 msg.cmd = IPC_ROUTER_CTRL_CMD_RESUME_TX;
1846 msg.cli.node_id = resume_tx_node_id;
1847 msg.cli.port_id = resume_tx_port_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001848
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06001849 RR("x RESUME_TX id=%d:%08x\n",
1850 msg.cli.node_id, msg.cli.port_id);
1851 msm_ipc_router_send_control_msg(xprt_info, &msg);
1852 }
1853
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001854 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001855 return;
1856
1857fail_data:
1858 release_pkt(pkt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001859 pr_err("ipc_router has died\n");
1860}
1861
1862int msm_ipc_router_register_server(struct msm_ipc_port *port_ptr,
1863 struct msm_ipc_addr *name)
1864{
1865 struct msm_ipc_server *server;
1866 unsigned long flags;
1867 union rr_control_msg ctl;
1868
1869 if (!port_ptr || !name)
1870 return -EINVAL;
1871
1872 if (name->addrtype != MSM_IPC_ADDR_NAME)
1873 return -EINVAL;
1874
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001875 down_write(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001876 server = msm_ipc_router_lookup_server(name->addr.port_name.service,
1877 name->addr.port_name.instance,
1878 IPC_ROUTER_NID_LOCAL,
1879 port_ptr->this_port.port_id);
1880 if (server) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001881 up_write(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001882 pr_err("%s: Server already present\n", __func__);
1883 return -EINVAL;
1884 }
1885
1886 server = msm_ipc_router_create_server(name->addr.port_name.service,
1887 name->addr.port_name.instance,
1888 IPC_ROUTER_NID_LOCAL,
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06001889 port_ptr->this_port.port_id,
1890 NULL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001891 if (!server) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001892 up_write(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001893 pr_err("%s: Server Creation failed\n", __func__);
1894 return -EINVAL;
1895 }
1896
1897 ctl.cmd = IPC_ROUTER_CTRL_CMD_NEW_SERVER;
1898 ctl.srv.service = server->name.service;
1899 ctl.srv.instance = server->name.instance;
1900 ctl.srv.node_id = IPC_ROUTER_NID_LOCAL;
1901 ctl.srv.port_id = port_ptr->this_port.port_id;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001902 up_write(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001903 broadcast_ctl_msg(&ctl);
1904 spin_lock_irqsave(&port_ptr->port_lock, flags);
1905 port_ptr->type = SERVER_PORT;
Karthikeyan Ramasubramaniandc9c4442013-05-02 17:25:54 -06001906 port_ptr->mode_info.mode = MULTI_LINK_MODE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001907 port_ptr->port_name.service = server->name.service;
1908 port_ptr->port_name.instance = server->name.instance;
1909 spin_unlock_irqrestore(&port_ptr->port_lock, flags);
1910 return 0;
1911}
1912
1913int msm_ipc_router_unregister_server(struct msm_ipc_port *port_ptr)
1914{
1915 struct msm_ipc_server *server;
1916 unsigned long flags;
1917 union rr_control_msg ctl;
1918
1919 if (!port_ptr)
1920 return -EINVAL;
1921
1922 if (port_ptr->type != SERVER_PORT) {
1923 pr_err("%s: Trying to unregister a non-server port\n",
1924 __func__);
1925 return -EINVAL;
1926 }
1927
1928 if (port_ptr->this_port.node_id != IPC_ROUTER_NID_LOCAL) {
1929 pr_err("%s: Trying to unregister a remote server locally\n",
1930 __func__);
1931 return -EINVAL;
1932 }
1933
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001934 down_write(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001935 server = msm_ipc_router_lookup_server(port_ptr->port_name.service,
1936 port_ptr->port_name.instance,
1937 port_ptr->this_port.node_id,
1938 port_ptr->this_port.port_id);
1939 if (!server) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001940 up_write(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001941 pr_err("%s: Server lookup failed\n", __func__);
1942 return -ENODEV;
1943 }
1944
1945 ctl.cmd = IPC_ROUTER_CTRL_CMD_REMOVE_SERVER;
1946 ctl.srv.service = server->name.service;
1947 ctl.srv.instance = server->name.instance;
1948 ctl.srv.node_id = IPC_ROUTER_NID_LOCAL;
1949 ctl.srv.port_id = port_ptr->this_port.port_id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001950 msm_ipc_router_destroy_server(server, port_ptr->this_port.node_id,
1951 port_ptr->this_port.port_id);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06001952 up_write(&server_list_lock_lha2);
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -06001953 broadcast_ctl_msg(&ctl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001954 spin_lock_irqsave(&port_ptr->port_lock, flags);
1955 port_ptr->type = CLIENT_PORT;
1956 spin_unlock_irqrestore(&port_ptr->port_lock, flags);
1957 return 0;
1958}
1959
1960static int loopback_data(struct msm_ipc_port *src,
1961 uint32_t port_id,
1962 struct sk_buff_head *data)
1963{
1964 struct sk_buff *head_skb;
1965 struct rr_header *hdr;
1966 struct msm_ipc_port *port_ptr;
1967 struct rr_packet *pkt;
Karthikeyan Ramasubramanian0a801c12013-02-08 13:07:42 -07001968 int ret_len;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001969
1970 if (!data) {
1971 pr_err("%s: Invalid pkt pointer\n", __func__);
1972 return -EINVAL;
1973 }
1974
1975 pkt = create_pkt(data);
1976 if (!pkt) {
1977 pr_err("%s: New pkt create failed\n", __func__);
1978 return -ENOMEM;
1979 }
1980
1981 head_skb = skb_peek(pkt->pkt_fragment_q);
Karthikeyan Ramasubramanian9024dd82011-12-19 18:44:19 -07001982 if (!head_skb) {
1983 pr_err("%s: pkt_fragment_q is empty\n", __func__);
Brent Hronik0e83d3b2013-05-01 16:25:00 -06001984 release_pkt(pkt);
Karthikeyan Ramasubramanian9024dd82011-12-19 18:44:19 -07001985 return -EINVAL;
1986 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001987 hdr = (struct rr_header *)skb_push(head_skb, IPC_ROUTER_HDR_SIZE);
1988 if (!hdr) {
1989 pr_err("%s: Prepend Header failed\n", __func__);
1990 release_pkt(pkt);
1991 return -ENOMEM;
1992 }
1993 hdr->version = IPC_ROUTER_VERSION;
1994 hdr->type = IPC_ROUTER_CTRL_CMD_DATA;
1995 hdr->src_node_id = src->this_port.node_id;
1996 hdr->src_port_id = src->this_port.port_id;
1997 hdr->size = pkt->length;
1998 hdr->confirm_rx = 0;
1999 hdr->dst_node_id = IPC_ROUTER_NID_LOCAL;
2000 hdr->dst_port_id = port_id;
2001 pkt->length += IPC_ROUTER_HDR_SIZE;
2002
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002003 down_read(&local_ports_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002004 port_ptr = msm_ipc_router_lookup_local_port(port_id);
2005 if (!port_ptr) {
2006 pr_err("%s: Local port %d not present\n", __func__, port_id);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002007 up_read(&local_ports_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002008 release_pkt(pkt);
2009 return -ENODEV;
2010 }
2011
Karthikeyan Ramasubramanian0a801c12013-02-08 13:07:42 -07002012 ret_len = pkt->length;
Karthikeyan Ramasubramaniand1af6252013-05-17 15:19:56 -06002013 post_pkt_to_port(port_ptr, pkt, 0);
Karthikeyan Ramasubramaniandc9c4442013-05-02 17:25:54 -06002014 update_comm_mode_info(&src->mode_info, NULL);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002015 up_read(&local_ports_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002016
Karthikeyan Ramasubramanian0a801c12013-02-08 13:07:42 -07002017 return ret_len;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002018}
2019
2020static int msm_ipc_router_write_pkt(struct msm_ipc_port *src,
2021 struct msm_ipc_router_remote_port *rport_ptr,
2022 struct rr_packet *pkt)
2023{
2024 struct sk_buff *head_skb;
2025 struct rr_header *hdr;
2026 struct msm_ipc_router_xprt_info *xprt_info;
2027 struct msm_ipc_routing_table_entry *rt_entry;
Zaheerulla Meera34fc662013-04-17 01:16:47 +05302028 struct msm_ipc_resume_tx_port *resume_tx_port;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002029 int ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002030
2031 if (!rport_ptr || !src || !pkt)
2032 return -EINVAL;
2033
2034 head_skb = skb_peek(pkt->pkt_fragment_q);
Karthikeyan Ramasubramanian9024dd82011-12-19 18:44:19 -07002035 if (!head_skb) {
2036 pr_err("%s: pkt_fragment_q is empty\n", __func__);
2037 return -EINVAL;
2038 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002039 hdr = (struct rr_header *)skb_push(head_skb, IPC_ROUTER_HDR_SIZE);
2040 if (!hdr) {
2041 pr_err("%s: Prepend Header failed\n", __func__);
2042 return -ENOMEM;
2043 }
2044 hdr->version = IPC_ROUTER_VERSION;
2045 hdr->type = IPC_ROUTER_CTRL_CMD_DATA;
2046 hdr->src_node_id = src->this_port.node_id;
2047 hdr->src_port_id = src->this_port.port_id;
2048 hdr->size = pkt->length;
2049 hdr->confirm_rx = 0;
2050 hdr->dst_node_id = rport_ptr->node_id;
2051 hdr->dst_port_id = rport_ptr->port_id;
2052 pkt->length += IPC_ROUTER_HDR_SIZE;
2053
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002054 mutex_lock(&rport_ptr->quota_lock_lhb2);
Zaheerulla Meera34fc662013-04-17 01:16:47 +05302055 if (rport_ptr->tx_quota_cnt == IPC_ROUTER_DEFAULT_RX_QUOTA) {
2056 if (msm_ipc_router_lookup_resume_tx_port(
2057 rport_ptr, src->this_port.port_id)) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002058 mutex_unlock(&rport_ptr->quota_lock_lhb2);
Zaheerulla Meera34fc662013-04-17 01:16:47 +05302059 return -EAGAIN;
2060 }
2061 resume_tx_port =
2062 kzalloc(sizeof(struct msm_ipc_resume_tx_port),
2063 GFP_KERNEL);
2064 if (!resume_tx_port) {
2065 pr_err("%s: Resume_Tx port allocation failed\n",
2066 __func__);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002067 mutex_unlock(&rport_ptr->quota_lock_lhb2);
Zaheerulla Meera34fc662013-04-17 01:16:47 +05302068 return -ENOMEM;
2069 }
2070 INIT_LIST_HEAD(&resume_tx_port->list);
2071 resume_tx_port->port_id = src->this_port.port_id;
2072 resume_tx_port->node_id = src->this_port.node_id;
2073 list_add_tail(&resume_tx_port->list,
2074 &rport_ptr->resume_tx_port_list);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002075 mutex_unlock(&rport_ptr->quota_lock_lhb2);
Zaheerulla Meera34fc662013-04-17 01:16:47 +05302076 return -EAGAIN;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002077 }
2078 rport_ptr->tx_quota_cnt++;
2079 if (rport_ptr->tx_quota_cnt == IPC_ROUTER_DEFAULT_RX_QUOTA)
2080 hdr->confirm_rx = 1;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002081 mutex_unlock(&rport_ptr->quota_lock_lhb2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002082
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002083 rt_entry = lookup_routing_table(hdr->dst_node_id);
2084 if (!rt_entry || !rt_entry->xprt_info) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002085 pr_err("%s: Remote node %d not up\n",
2086 __func__, hdr->dst_node_id);
2087 return -ENODEV;
2088 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002089 down_read(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002090 xprt_info = rt_entry->xprt_info;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002091 mutex_lock(&xprt_info->tx_lock_lhb2);
Karthikeyan Ramasubramanian8cec5922012-02-16 17:41:58 -07002092 ret = xprt_info->xprt->write(pkt, pkt->length, xprt_info->xprt);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002093 mutex_unlock(&xprt_info->tx_lock_lhb2);
2094 up_read(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002095
2096 if (ret < 0) {
2097 pr_err("%s: Write on XPRT failed\n", __func__);
2098 return ret;
2099 }
Karthikeyan Ramasubramaniandc9c4442013-05-02 17:25:54 -06002100 update_comm_mode_info(&src->mode_info, xprt_info);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002101
2102 RAW_HDR("[w rr_h] "
2103 "ver=%i,type=%s,src_nid=%08x,src_port_id=%08x,"
2104 "confirm_rx=%i,size=%3i,dst_pid=%08x,dst_cid=%08x\n",
2105 hdr->version, type_to_str(hdr->type),
2106 hdr->src_node_id, hdr->src_port_id,
2107 hdr->confirm_rx, hdr->size,
2108 hdr->dst_node_id, hdr->dst_port_id);
2109
2110#if defined(CONFIG_MSM_SMD_LOGGING)
2111#if defined(DEBUG)
2112 if (msm_ipc_router_debug_mask & SMEM_LOG) {
2113 smem_log_event((SMEM_LOG_PROC_ID_APPS |
2114 SMEM_LOG_RPC_ROUTER_EVENT_BASE |
2115 IPC_ROUTER_LOG_EVENT_TX),
2116 (hdr->src_node_id << 24) |
2117 (hdr->src_port_id & 0xffffff),
2118 (hdr->dst_node_id << 24) |
2119 (hdr->dst_port_id & 0xffffff),
2120 (hdr->type << 24) | (hdr->confirm_rx << 16) |
2121 (hdr->size & 0xffff));
2122 }
2123#endif
2124#endif
2125
2126 return pkt->length;
2127}
2128
2129int msm_ipc_router_send_to(struct msm_ipc_port *src,
2130 struct sk_buff_head *data,
2131 struct msm_ipc_addr *dest)
2132{
2133 uint32_t dst_node_id = 0, dst_port_id = 0;
2134 struct msm_ipc_server *server;
2135 struct msm_ipc_server_port *server_port;
2136 struct msm_ipc_router_remote_port *rport_ptr = NULL;
2137 struct rr_packet *pkt;
2138 int ret;
2139
2140 if (!src || !data || !dest) {
2141 pr_err("%s: Invalid Parameters\n", __func__);
2142 return -EINVAL;
2143 }
2144
2145 /* Resolve Address*/
2146 if (dest->addrtype == MSM_IPC_ADDR_ID) {
2147 dst_node_id = dest->addr.port_addr.node_id;
2148 dst_port_id = dest->addr.port_addr.port_id;
2149 } else if (dest->addrtype == MSM_IPC_ADDR_NAME) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002150 down_read(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002151 server = msm_ipc_router_lookup_server(
2152 dest->addr.port_name.service,
2153 dest->addr.port_name.instance,
2154 0, 0);
2155 if (!server) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002156 up_read(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002157 pr_err("%s: Destination not reachable\n", __func__);
2158 return -ENODEV;
2159 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002160 server_port = list_first_entry(&server->server_port_list,
2161 struct msm_ipc_server_port,
2162 list);
2163 dst_node_id = server_port->server_addr.node_id;
2164 dst_port_id = server_port->server_addr.port_id;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002165 up_read(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002166 }
2167 if (dst_node_id == IPC_ROUTER_NID_LOCAL) {
2168 ret = loopback_data(src, dst_port_id, data);
2169 return ret;
2170 }
2171
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002172 down_read(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002173 rport_ptr = msm_ipc_router_lookup_remote_port(dst_node_id,
2174 dst_port_id);
2175 if (!rport_ptr) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002176 up_read(&routing_table_lock_lha3);
Zaheerulla Meer2c515312013-05-10 15:51:28 +05302177 pr_err("%s: Remote port not found\n", __func__);
2178 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002179 }
2180
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -06002181 if (src->check_send_permissions) {
2182 ret = src->check_send_permissions(rport_ptr->sec_rule);
2183 if (ret <= 0) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002184 up_read(&routing_table_lock_lha3);
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -06002185 pr_err("%s: permission failure for %s\n",
2186 __func__, current->comm);
2187 return -EPERM;
2188 }
2189 }
2190
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002191 pkt = create_pkt(data);
2192 if (!pkt) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002193 up_read(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002194 pr_err("%s: Pkt creation failed\n", __func__);
2195 return -ENOMEM;
2196 }
2197
2198 ret = msm_ipc_router_write_pkt(src, rport_ptr, pkt);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002199 up_read(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002200 release_pkt(pkt);
2201
2202 return ret;
2203}
2204
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -06002205int msm_ipc_router_send_msg(struct msm_ipc_port *src,
2206 struct msm_ipc_addr *dest,
2207 void *data, unsigned int data_len)
2208{
2209 struct sk_buff_head *out_skb_head;
2210 int ret;
2211
2212 out_skb_head = msm_ipc_router_buf_to_skb(data, data_len);
2213 if (!out_skb_head) {
2214 pr_err("%s: SKB conversion failed\n", __func__);
2215 return -EFAULT;
2216 }
2217
2218 ret = msm_ipc_router_send_to(src, out_skb_head, dest);
2219 if (ret < 0) {
2220 pr_err("%s: msm_ipc_router_send_to failed - ret: %d\n",
2221 __func__, ret);
2222 msm_ipc_router_free_skb(out_skb_head);
2223 }
2224 return 0;
2225}
2226
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002227int msm_ipc_router_read(struct msm_ipc_port *port_ptr,
2228 struct sk_buff_head **data,
2229 size_t buf_len)
2230{
2231 struct rr_packet *pkt;
2232 int ret;
2233
2234 if (!port_ptr || !data)
2235 return -EINVAL;
2236
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002237 mutex_lock(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002238 if (list_empty(&port_ptr->port_rx_q)) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002239 mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002240 return -EAGAIN;
2241 }
2242
2243 pkt = list_first_entry(&port_ptr->port_rx_q, struct rr_packet, list);
2244 if ((buf_len) && ((pkt->length - IPC_ROUTER_HDR_SIZE) > buf_len)) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002245 mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002246 return -ETOOSMALL;
2247 }
2248 list_del(&pkt->list);
2249 if (list_empty(&port_ptr->port_rx_q))
2250 wake_unlock(&port_ptr->port_rx_wake_lock);
2251 *data = pkt->pkt_fragment_q;
2252 ret = pkt->length;
2253 kfree(pkt);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002254 mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002255
2256 return ret;
2257}
2258
Zaheerulla Meer20e84262013-05-22 23:31:59 +05302259/**
2260 * msm_ipc_router_recv_from() - Recieve messages destined to a local port.
2261 * @port_ptr: Pointer to the local port
2262 * @data : Pointer to the socket buffer head
2263 * @src: Pointer to local port address
2264 * @timeout: < 0 timeout indicates infinite wait till a message arrives.
2265 * > 0 timeout indicates the wait time.
2266 * 0 indicates that we do not wait.
2267 * @return: = Number of bytes read(On successful read operation).
2268 * = 0 (If there are no pending messages and timeout is 0).
2269 * = -EINVAL (If either of the arguments, port_ptr or data is invalid)
2270 * = -EFAULT (If there are no pending messages when timeout is > 0
2271 * and the wait_event_interruptible_timeout has returned value > 0)
2272 * = -ERESTARTSYS (If there are no pending messages when timeout
2273 * is < 0 and wait_event_interruptible was interrupted by a signal)
2274 *
2275 * This function reads the messages that are destined for a local port. It
2276 * is used by modules that exist with-in the kernel and use IPC Router for
2277 * transport. The function checks if there are any messages that are already
2278 * received. If yes, it reads them, else it waits as per the timeout value.
2279 * On a successful read, the return value of the function indicates the number
2280 * of bytes that are read.
2281 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002282int msm_ipc_router_recv_from(struct msm_ipc_port *port_ptr,
2283 struct sk_buff_head **data,
2284 struct msm_ipc_addr *src,
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -06002285 long timeout)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002286{
2287 int ret, data_len, align_size;
2288 struct sk_buff *temp_skb;
2289 struct rr_header *hdr = NULL;
2290
2291 if (!port_ptr || !data) {
2292 pr_err("%s: Invalid pointers being passed\n", __func__);
2293 return -EINVAL;
2294 }
2295
2296 *data = NULL;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002297 mutex_lock(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002298 while (list_empty(&port_ptr->port_rx_q)) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002299 mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002300 if (timeout < 0) {
2301 ret = wait_event_interruptible(
2302 port_ptr->port_rx_wait_q,
2303 !list_empty(&port_ptr->port_rx_q));
2304 if (ret)
2305 return ret;
2306 } else if (timeout > 0) {
2307 timeout = wait_event_interruptible_timeout(
2308 port_ptr->port_rx_wait_q,
2309 !list_empty(&port_ptr->port_rx_q),
2310 timeout);
2311 if (timeout < 0)
2312 return -EFAULT;
2313 }
2314 if (timeout == 0)
Zaheerulla Meer20e84262013-05-22 23:31:59 +05302315 return 0;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002316 mutex_lock(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002317 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002318 mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002319
2320 ret = msm_ipc_router_read(port_ptr, data, 0);
2321 if (ret <= 0 || !(*data))
2322 return ret;
2323
2324 temp_skb = skb_peek(*data);
2325 hdr = (struct rr_header *)(temp_skb->data);
2326 if (src) {
2327 src->addrtype = MSM_IPC_ADDR_ID;
2328 src->addr.port_addr.node_id = hdr->src_node_id;
2329 src->addr.port_addr.port_id = hdr->src_port_id;
2330 }
2331
2332 data_len = hdr->size;
2333 skb_pull(temp_skb, IPC_ROUTER_HDR_SIZE);
2334 align_size = ALIGN_SIZE(data_len);
2335 if (align_size) {
2336 temp_skb = skb_peek_tail(*data);
2337 skb_trim(temp_skb, (temp_skb->len - align_size));
2338 }
2339 return data_len;
2340}
2341
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -06002342int msm_ipc_router_read_msg(struct msm_ipc_port *port_ptr,
2343 struct msm_ipc_addr *src,
2344 unsigned char **data,
2345 unsigned int *len)
2346{
2347 struct sk_buff_head *in_skb_head;
2348 int ret;
2349
Zaheerulla Meer20e84262013-05-22 23:31:59 +05302350 ret = msm_ipc_router_recv_from(port_ptr, &in_skb_head, src, 0);
2351
2352 if (ret == 0)
2353 return -ENOMSG;
2354
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -06002355 if (ret < 0) {
2356 pr_err("%s: msm_ipc_router_recv_from failed - ret: %d\n",
2357 __func__, ret);
2358 return ret;
2359 }
2360
2361 *data = msm_ipc_router_skb_to_buf(in_skb_head, ret);
2362 if (!(*data))
2363 pr_err("%s: Buf conversion failed\n", __func__);
2364
2365 *len = ret;
2366 msm_ipc_router_free_skb(in_skb_head);
2367 return 0;
2368}
2369
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002370struct msm_ipc_port *msm_ipc_router_create_port(
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -06002371 void (*notify)(unsigned event, void *priv),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002372 void *priv)
2373{
2374 struct msm_ipc_port *port_ptr;
Karthikeyan Ramasubramanian70444192012-07-12 10:25:49 -06002375 int ret;
2376
2377 ret = wait_for_completion_interruptible(&msm_ipc_local_router_up);
2378 if (ret < 0) {
2379 pr_err("%s: Error waiting for local router\n", __func__);
2380 return NULL;
2381 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002382
2383 port_ptr = msm_ipc_router_create_raw_port(NULL, notify, priv);
2384 if (!port_ptr)
2385 pr_err("%s: port_ptr alloc failed\n", __func__);
2386
2387 return port_ptr;
2388}
2389
2390int msm_ipc_router_close_port(struct msm_ipc_port *port_ptr)
2391{
2392 union rr_control_msg msg;
2393 struct rr_packet *pkt, *temp_pkt;
2394 struct msm_ipc_server *server;
2395
2396 if (!port_ptr)
2397 return -EINVAL;
2398
2399 if (port_ptr->type == SERVER_PORT || port_ptr->type == CLIENT_PORT) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002400 down_write(&local_ports_lock_lha2);
Karthikeyan Ramasubramanianbe9954b2012-06-13 12:59:54 -06002401 list_del(&port_ptr->list);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002402 up_write(&local_ports_lock_lha2);
Karthikeyan Ramasubramanianbe9954b2012-06-13 12:59:54 -06002403
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002404 if (port_ptr->type == SERVER_PORT) {
2405 msg.cmd = IPC_ROUTER_CTRL_CMD_REMOVE_SERVER;
2406 msg.srv.service = port_ptr->port_name.service;
2407 msg.srv.instance = port_ptr->port_name.instance;
2408 msg.srv.node_id = port_ptr->this_port.node_id;
2409 msg.srv.port_id = port_ptr->this_port.port_id;
2410 RR("x REMOVE_SERVER Name=%d:%08x Id=%d:%08x\n",
2411 msg.srv.service, msg.srv.instance,
2412 msg.srv.node_id, msg.srv.port_id);
Karthikeyan Ramasubramanian25e91872013-01-10 17:09:13 -07002413 broadcast_ctl_msg(&msg);
2414 broadcast_ctl_msg_locally(&msg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002415 }
Karthikeyan Ramasubramanian25e91872013-01-10 17:09:13 -07002416
2417 /*
2418 * Server port could have been a client port earlier.
2419 * Send REMOVE_CLIENT message in either case.
2420 */
Karthikeyan Ramasubramanian25e91872013-01-10 17:09:13 -07002421 RR("x REMOVE_CLIENT id=%d:%08x\n",
Karthikeyan Ramasubramaniandc9c4442013-05-02 17:25:54 -06002422 port_ptr->this_port.node_id, port_ptr->this_port.port_id);
2423 msm_ipc_router_send_remove_client(&port_ptr->mode_info,
2424 port_ptr->this_port.node_id,
2425 port_ptr->this_port.port_id);
Karthikeyan Ramasubramanianbe9954b2012-06-13 12:59:54 -06002426 } else if (port_ptr->type == CONTROL_PORT) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002427 down_write(&control_ports_lock_lha5);
Karthikeyan Ramasubramanianbe9954b2012-06-13 12:59:54 -06002428 list_del(&port_ptr->list);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002429 up_write(&control_ports_lock_lha5);
Karthikeyan Ramasubramaniand6dbfae2013-01-16 09:00:28 -07002430 } else if (port_ptr->type == IRSC_PORT) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002431 down_write(&local_ports_lock_lha2);
Karthikeyan Ramasubramaniand6dbfae2013-01-16 09:00:28 -07002432 list_del(&port_ptr->list);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002433 up_write(&local_ports_lock_lha2);
Karthikeyan Ramasubramaniand6dbfae2013-01-16 09:00:28 -07002434 signal_irsc_completion();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002435 }
2436
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002437 mutex_lock(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002438 list_for_each_entry_safe(pkt, temp_pkt, &port_ptr->port_rx_q, list) {
2439 list_del(&pkt->list);
2440 release_pkt(pkt);
2441 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002442 mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002443
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002444 if (port_ptr->type == SERVER_PORT) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002445 down_write(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002446 server = msm_ipc_router_lookup_server(
2447 port_ptr->port_name.service,
2448 port_ptr->port_name.instance,
2449 port_ptr->this_port.node_id,
2450 port_ptr->this_port.port_id);
2451 if (server)
2452 msm_ipc_router_destroy_server(server,
2453 port_ptr->this_port.node_id,
2454 port_ptr->this_port.port_id);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002455 up_write(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002456 }
2457
Karthikeyan Ramasubramaniandd8c3b52011-11-30 16:26:12 -07002458 wake_lock_destroy(&port_ptr->port_rx_wake_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002459 kfree(port_ptr);
2460 return 0;
2461}
2462
2463int msm_ipc_router_get_curr_pkt_size(struct msm_ipc_port *port_ptr)
2464{
2465 struct rr_packet *pkt;
2466 int rc = 0;
2467
2468 if (!port_ptr)
2469 return -EINVAL;
2470
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002471 mutex_lock(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002472 if (!list_empty(&port_ptr->port_rx_q)) {
2473 pkt = list_first_entry(&port_ptr->port_rx_q,
2474 struct rr_packet, list);
2475 rc = pkt->length;
2476 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002477 mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002478
2479 return rc;
2480}
2481
2482int msm_ipc_router_bind_control_port(struct msm_ipc_port *port_ptr)
2483{
2484 if (!port_ptr)
2485 return -EINVAL;
2486
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002487 down_write(&local_ports_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002488 list_del(&port_ptr->list);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002489 up_write(&local_ports_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002490 port_ptr->type = CONTROL_PORT;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002491 down_write(&control_ports_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002492 list_add_tail(&port_ptr->list, &control_ports);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002493 up_write(&control_ports_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002494
2495 return 0;
2496}
2497
2498int msm_ipc_router_lookup_server_name(struct msm_ipc_port_name *srv_name,
Karthikeyan Ramasubramaniandfde01b2012-06-12 14:25:13 -06002499 struct msm_ipc_server_info *srv_info,
Karthikeyan Ramasubramaniancc450c92011-07-27 14:38:15 -06002500 int num_entries_in_array,
2501 uint32_t lookup_mask)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002502{
2503 struct msm_ipc_server *server;
2504 struct msm_ipc_server_port *server_port;
Karthikeyan Ramasubramaniancc450c92011-07-27 14:38:15 -06002505 int key, i = 0; /*num_entries_found*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002506
2507 if (!srv_name) {
2508 pr_err("%s: Invalid srv_name\n", __func__);
2509 return -EINVAL;
2510 }
2511
Karthikeyan Ramasubramaniandfde01b2012-06-12 14:25:13 -06002512 if (num_entries_in_array && !srv_info) {
2513 pr_err("%s: srv_info NULL\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002514 return -EINVAL;
2515 }
2516
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002517 down_read(&server_list_lock_lha2);
Karthikeyan Ramasubramaniancc450c92011-07-27 14:38:15 -06002518 if (!lookup_mask)
2519 lookup_mask = 0xFFFFFFFF;
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -06002520 key = (srv_name->service & (SRV_HASH_SIZE - 1));
2521 list_for_each_entry(server, &server_list[key], list) {
2522 if ((server->name.service != srv_name->service) ||
2523 ((server->name.instance & lookup_mask) !=
2524 srv_name->instance))
2525 continue;
Karthikeyan Ramasubramaniancc450c92011-07-27 14:38:15 -06002526
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -06002527 list_for_each_entry(server_port,
2528 &server->server_port_list, list) {
2529 if (i < num_entries_in_array) {
2530 srv_info[i].node_id =
Karthikeyan Ramasubramaniancc450c92011-07-27 14:38:15 -06002531 server_port->server_addr.node_id;
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -06002532 srv_info[i].port_id =
Karthikeyan Ramasubramaniancc450c92011-07-27 14:38:15 -06002533 server_port->server_addr.port_id;
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -06002534 srv_info[i].service = server->name.service;
2535 srv_info[i].instance = server->name.instance;
Karthikeyan Ramasubramaniancc450c92011-07-27 14:38:15 -06002536 }
Karthikeyan Ramasubramaniana85d09f2012-10-25 15:40:45 -06002537 i++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002538 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002539 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002540 up_read(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002541
2542 return i;
2543}
2544
2545int msm_ipc_router_close(void)
2546{
2547 struct msm_ipc_router_xprt_info *xprt_info, *tmp_xprt_info;
2548
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002549 down_write(&xprt_info_list_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002550 list_for_each_entry_safe(xprt_info, tmp_xprt_info,
2551 &xprt_info_list, list) {
Karthikeyan Ramasubramanian8cec5922012-02-16 17:41:58 -07002552 xprt_info->xprt->close(xprt_info->xprt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002553 list_del(&xprt_info->list);
2554 kfree(xprt_info);
2555 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002556 up_write(&xprt_info_list_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002557 return 0;
2558}
2559
2560#if defined(CONFIG_DEBUG_FS)
2561static int dump_routing_table(char *buf, int max)
2562{
2563 int i = 0, j;
2564 struct msm_ipc_routing_table_entry *rt_entry;
2565
2566 for (j = 0; j < RT_HASH_SIZE; j++) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002567 down_read(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002568 list_for_each_entry(rt_entry, &routing_table[j], list) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002569 down_read(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002570 i += scnprintf(buf + i, max - i,
2571 "Node Id: 0x%08x\n", rt_entry->node_id);
Karthikeyan Ramasubramanianc1a4e3a2012-09-10 16:10:24 -06002572 if (rt_entry->node_id == IPC_ROUTER_NID_LOCAL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002573 i += scnprintf(buf + i, max - i,
2574 "XPRT Name: Loopback\n");
2575 i += scnprintf(buf + i, max - i,
2576 "Next Hop: %d\n", rt_entry->node_id);
2577 } else {
2578 i += scnprintf(buf + i, max - i,
2579 "XPRT Name: %s\n",
2580 rt_entry->xprt_info->xprt->name);
2581 i += scnprintf(buf + i, max - i,
2582 "Next Hop: 0x%08x\n",
2583 rt_entry->xprt_info->remote_node_id);
2584 }
2585 i += scnprintf(buf + i, max - i, "\n");
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002586 up_read(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002587 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002588 up_read(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002589 }
2590
2591 return i;
2592}
2593
2594static int dump_xprt_info(char *buf, int max)
2595{
2596 int i = 0;
2597 struct msm_ipc_router_xprt_info *xprt_info;
2598
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002599 down_read(&xprt_info_list_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002600 list_for_each_entry(xprt_info, &xprt_info_list, list) {
2601 i += scnprintf(buf + i, max - i, "XPRT Name: %s\n",
2602 xprt_info->xprt->name);
2603 i += scnprintf(buf + i, max - i, "Link Id: %d\n",
2604 xprt_info->xprt->link_id);
2605 i += scnprintf(buf + i, max - i, "Initialized: %s\n",
2606 (xprt_info->initialized ? "Y" : "N"));
2607 i += scnprintf(buf + i, max - i, "Remote Node Id: 0x%08x\n",
2608 xprt_info->remote_node_id);
2609 i += scnprintf(buf + i, max - i, "\n");
2610 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002611 up_read(&xprt_info_list_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002612
2613 return i;
2614}
2615
2616static int dump_servers(char *buf, int max)
2617{
2618 int i = 0, j;
2619 struct msm_ipc_server *server;
2620 struct msm_ipc_server_port *server_port;
2621
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002622 down_read(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002623 for (j = 0; j < SRV_HASH_SIZE; j++) {
2624 list_for_each_entry(server, &server_list[j], list) {
2625 list_for_each_entry(server_port,
2626 &server->server_port_list,
2627 list) {
2628 i += scnprintf(buf + i, max - i, "Service: "
2629 "0x%08x\n", server->name.service);
2630 i += scnprintf(buf + i, max - i, "Instance: "
2631 "0x%08x\n", server->name.instance);
2632 i += scnprintf(buf + i, max - i,
2633 "Node_id: 0x%08x\n",
2634 server_port->server_addr.node_id);
2635 i += scnprintf(buf + i, max - i,
2636 "Port_id: 0x%08x\n",
2637 server_port->server_addr.port_id);
2638 i += scnprintf(buf + i, max - i, "\n");
2639 }
2640 }
2641 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002642 up_read(&server_list_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002643
2644 return i;
2645}
2646
2647static int dump_remote_ports(char *buf, int max)
2648{
2649 int i = 0, j, k;
2650 struct msm_ipc_router_remote_port *rport_ptr;
2651 struct msm_ipc_routing_table_entry *rt_entry;
2652
2653 for (j = 0; j < RT_HASH_SIZE; j++) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002654 down_read(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002655 list_for_each_entry(rt_entry, &routing_table[j], list) {
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002656 down_read(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002657 for (k = 0; k < RP_HASH_SIZE; k++) {
2658 list_for_each_entry(rport_ptr,
2659 &rt_entry->remote_port_list[k],
2660 list) {
2661 i += scnprintf(buf + i, max - i,
2662 "Node_id: 0x%08x\n",
2663 rport_ptr->node_id);
2664 i += scnprintf(buf + i, max - i,
2665 "Port_id: 0x%08x\n",
2666 rport_ptr->port_id);
2667 i += scnprintf(buf + i, max - i,
2668 "Quota_cnt: %d\n",
2669 rport_ptr->tx_quota_cnt);
2670 i += scnprintf(buf + i, max - i, "\n");
2671 }
2672 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002673 up_read(&rt_entry->lock_lha4);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002674 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002675 up_read(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002676 }
2677
2678 return i;
2679}
2680
2681static int dump_control_ports(char *buf, int max)
2682{
2683 int i = 0;
2684 struct msm_ipc_port *port_ptr;
2685
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002686 down_read(&control_ports_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002687 list_for_each_entry(port_ptr, &control_ports, list) {
2688 i += scnprintf(buf + i, max - i, "Node_id: 0x%08x\n",
2689 port_ptr->this_port.node_id);
2690 i += scnprintf(buf + i, max - i, "Port_id: 0x%08x\n",
2691 port_ptr->this_port.port_id);
2692 i += scnprintf(buf + i, max - i, "\n");
2693 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002694 up_read(&control_ports_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002695
2696 return i;
2697}
2698
2699static int dump_local_ports(char *buf, int max)
2700{
2701 int i = 0, j;
2702 unsigned long flags;
2703 struct msm_ipc_port *port_ptr;
2704
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002705 down_read(&local_ports_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002706 for (j = 0; j < LP_HASH_SIZE; j++) {
2707 list_for_each_entry(port_ptr, &local_ports[j], list) {
2708 spin_lock_irqsave(&port_ptr->port_lock, flags);
2709 i += scnprintf(buf + i, max - i, "Node_id: 0x%08x\n",
2710 port_ptr->this_port.node_id);
2711 i += scnprintf(buf + i, max - i, "Port_id: 0x%08x\n",
2712 port_ptr->this_port.port_id);
2713 i += scnprintf(buf + i, max - i, "# pkts tx'd %d\n",
2714 port_ptr->num_tx);
2715 i += scnprintf(buf + i, max - i, "# pkts rx'd %d\n",
2716 port_ptr->num_rx);
2717 i += scnprintf(buf + i, max - i, "# bytes tx'd %ld\n",
2718 port_ptr->num_tx_bytes);
2719 i += scnprintf(buf + i, max - i, "# bytes rx'd %ld\n",
2720 port_ptr->num_rx_bytes);
2721 spin_unlock_irqrestore(&port_ptr->port_lock, flags);
2722 i += scnprintf(buf + i, max - i, "\n");
2723 }
2724 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002725 up_read(&local_ports_lock_lha2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002726
2727 return i;
2728}
2729
2730#define DEBUG_BUFMAX 4096
2731static char debug_buffer[DEBUG_BUFMAX];
2732
2733static ssize_t debug_read(struct file *file, char __user *buf,
2734 size_t count, loff_t *ppos)
2735{
2736 int (*fill)(char *buf, int max) = file->private_data;
2737 int bsize = fill(debug_buffer, DEBUG_BUFMAX);
2738 return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
2739}
2740
2741static int debug_open(struct inode *inode, struct file *file)
2742{
2743 file->private_data = inode->i_private;
2744 return 0;
2745}
2746
2747static const struct file_operations debug_ops = {
2748 .read = debug_read,
2749 .open = debug_open,
2750};
2751
2752static void debug_create(const char *name, mode_t mode,
2753 struct dentry *dent,
2754 int (*fill)(char *buf, int max))
2755{
2756 debugfs_create_file(name, mode, dent, fill, &debug_ops);
2757}
2758
2759static void debugfs_init(void)
2760{
2761 struct dentry *dent;
2762
2763 dent = debugfs_create_dir("msm_ipc_router", 0);
2764 if (IS_ERR(dent))
2765 return;
2766
2767 debug_create("dump_local_ports", 0444, dent,
2768 dump_local_ports);
2769 debug_create("dump_remote_ports", 0444, dent,
2770 dump_remote_ports);
2771 debug_create("dump_control_ports", 0444, dent,
2772 dump_control_ports);
2773 debug_create("dump_servers", 0444, dent,
2774 dump_servers);
2775 debug_create("dump_xprt_info", 0444, dent,
2776 dump_xprt_info);
2777 debug_create("dump_routing_table", 0444, dent,
2778 dump_routing_table);
2779}
2780
2781#else
2782static void debugfs_init(void) {}
2783#endif
2784
2785static int msm_ipc_router_add_xprt(struct msm_ipc_router_xprt *xprt)
2786{
2787 struct msm_ipc_router_xprt_info *xprt_info;
2788 struct msm_ipc_routing_table_entry *rt_entry;
2789
2790 xprt_info = kmalloc(sizeof(struct msm_ipc_router_xprt_info),
2791 GFP_KERNEL);
2792 if (!xprt_info)
2793 return -ENOMEM;
2794
2795 xprt_info->xprt = xprt;
2796 xprt_info->initialized = 0;
2797 xprt_info->remote_node_id = -1;
2798 INIT_LIST_HEAD(&xprt_info->pkt_list);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002799 mutex_init(&xprt_info->rx_lock_lhb2);
2800 mutex_init(&xprt_info->tx_lock_lhb2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002801 wake_lock_init(&xprt_info->wakelock,
2802 WAKE_LOCK_SUSPEND, xprt->name);
2803 xprt_info->need_len = 0;
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002804 xprt_info->abort_data_read = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002805 INIT_WORK(&xprt_info->read_data, do_read_data);
2806 INIT_LIST_HEAD(&xprt_info->list);
2807
2808 xprt_info->workqueue = create_singlethread_workqueue(xprt->name);
2809 if (!xprt_info->workqueue) {
2810 kfree(xprt_info);
2811 return -ENOMEM;
2812 }
2813
2814 if (!strcmp(xprt->name, "msm_ipc_router_loopback_xprt")) {
2815 xprt_info->remote_node_id = IPC_ROUTER_NID_LOCAL;
2816 xprt_info->initialized = 1;
2817 }
2818
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002819 down_write(&xprt_info_list_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002820 list_add_tail(&xprt_info->list, &xprt_info_list);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002821 up_write(&xprt_info_list_lock_lha5);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002822
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002823 down_write(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002824 if (!routing_table_inited) {
2825 init_routing_table();
2826 rt_entry = alloc_routing_table_entry(IPC_ROUTER_NID_LOCAL);
2827 add_routing_table_entry(rt_entry);
2828 routing_table_inited = 1;
2829 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002830 up_write(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002831
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002832 xprt->priv = xprt_info;
2833
2834 return 0;
2835}
2836
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002837static void msm_ipc_router_remove_xprt(struct msm_ipc_router_xprt *xprt)
2838{
2839 struct msm_ipc_router_xprt_info *xprt_info;
2840
2841 if (xprt && xprt->priv) {
2842 xprt_info = xprt->priv;
2843
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002844 mutex_lock(&xprt_info->rx_lock_lhb2);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002845 xprt_info->abort_data_read = 1;
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002846 mutex_unlock(&xprt_info->rx_lock_lhb2);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002847
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002848 down_write(&xprt_info_list_lock_lha5);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002849 list_del(&xprt_info->list);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002850 up_write(&xprt_info_list_lock_lha5);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002851
2852 flush_workqueue(xprt_info->workqueue);
2853 destroy_workqueue(xprt_info->workqueue);
2854 wake_lock_destroy(&xprt_info->wakelock);
2855
2856 xprt->priv = 0;
2857 kfree(xprt_info);
2858 }
2859}
2860
2861
2862struct msm_ipc_router_xprt_work {
2863 struct msm_ipc_router_xprt *xprt;
2864 struct work_struct work;
2865};
2866
2867static void xprt_open_worker(struct work_struct *work)
2868{
2869 struct msm_ipc_router_xprt_work *xprt_work =
2870 container_of(work, struct msm_ipc_router_xprt_work, work);
2871
2872 msm_ipc_router_add_xprt(xprt_work->xprt);
2873 kfree(xprt_work);
2874}
2875
2876static void xprt_close_worker(struct work_struct *work)
2877{
2878 struct msm_ipc_router_xprt_work *xprt_work =
2879 container_of(work, struct msm_ipc_router_xprt_work, work);
2880
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002881 msm_ipc_cleanup_routing_table(xprt_work->xprt->priv);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002882 msm_ipc_router_remove_xprt(xprt_work->xprt);
Zaheerulla Meer35893a62013-06-19 16:54:44 +05302883 xprt_work->xprt->sft_close_done(xprt_work->xprt);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002884 kfree(xprt_work);
2885}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002886
2887void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt,
2888 unsigned event,
2889 void *data)
2890{
2891 struct msm_ipc_router_xprt_info *xprt_info = xprt->priv;
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002892 struct msm_ipc_router_xprt_work *xprt_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002893 struct rr_packet *pkt;
Karthikeyan Ramasubramanian4af9f7c2011-09-30 15:55:18 -06002894 unsigned long ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002895
Karthikeyan Ramasubramanian4af9f7c2011-09-30 15:55:18 -06002896 if (!msm_ipc_router_workqueue) {
2897 ret = wait_for_completion_timeout(&msm_ipc_local_router_up,
2898 IPC_ROUTER_INIT_TIMEOUT);
2899 if (!ret || !msm_ipc_router_workqueue) {
2900 pr_err("%s: IPC Router not initialized\n", __func__);
2901 return;
2902 }
2903 }
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002904
2905 switch (event) {
2906 case IPC_ROUTER_XPRT_EVENT_OPEN:
2907 D("open event for '%s'\n", xprt->name);
2908 xprt_work = kmalloc(sizeof(struct msm_ipc_router_xprt_work),
2909 GFP_ATOMIC);
Karthikeyan Ramasubramanianc51456c2013-05-16 15:51:29 -06002910 if (xprt_work) {
2911 xprt_work->xprt = xprt;
2912 INIT_WORK(&xprt_work->work, xprt_open_worker);
2913 queue_work(msm_ipc_router_workqueue, &xprt_work->work);
2914 } else {
2915 pr_err("%s: malloc failure - Couldn't notify OPEN event",
2916 __func__);
2917 }
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002918 break;
2919
2920 case IPC_ROUTER_XPRT_EVENT_CLOSE:
2921 D("close event for '%s'\n", xprt->name);
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002922 xprt_work = kmalloc(sizeof(struct msm_ipc_router_xprt_work),
2923 GFP_ATOMIC);
Karthikeyan Ramasubramanianc51456c2013-05-16 15:51:29 -06002924 if (xprt_work) {
2925 xprt_work->xprt = xprt;
2926 INIT_WORK(&xprt_work->work, xprt_close_worker);
2927 queue_work(msm_ipc_router_workqueue, &xprt_work->work);
2928 } else {
2929 pr_err("%s: malloc failure - Couldn't notify CLOSE event",
2930 __func__);
2931 }
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002932 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002933 }
2934
2935 if (!data)
2936 return;
2937
2938 while (!xprt_info) {
2939 msleep(100);
2940 xprt_info = xprt->priv;
2941 }
2942
2943 pkt = clone_pkt((struct rr_packet *)data);
2944 if (!pkt)
2945 return;
2946
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002947 mutex_lock(&xprt_info->rx_lock_lhb2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002948 list_add_tail(&pkt->list, &xprt_info->pkt_list);
2949 wake_lock(&xprt_info->wakelock);
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002950 mutex_unlock(&xprt_info->rx_lock_lhb2);
Karthikeyan Ramasubramanian872ecd82012-07-25 11:07:48 -06002951 queue_work(xprt_info->workqueue, &xprt_info->read_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002952}
2953
2954static int __init msm_ipc_router_init(void)
2955{
2956 int i, ret;
2957 struct msm_ipc_routing_table_entry *rt_entry;
2958
2959 msm_ipc_router_debug_mask |= SMEM_LOG;
Karthikeyan Ramasubramanian682ebcc2013-03-22 10:47:20 -06002960 ipc_rtr_log_ctxt = ipc_log_context_create(IPC_RTR_LOG_PAGES,
2961 "ipc_router");
2962 if (!ipc_rtr_log_ctxt)
2963 pr_err("%s: Unable to create IPC logging for IPC RTR",
2964 __func__);
2965
Karthikeyan Ramasubramanianff6fbae2011-06-09 11:13:19 -06002966 msm_ipc_router_workqueue =
2967 create_singlethread_workqueue("msm_ipc_router");
2968 if (!msm_ipc_router_workqueue)
2969 return -ENOMEM;
2970
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002971 debugfs_init();
2972
2973 for (i = 0; i < SRV_HASH_SIZE; i++)
2974 INIT_LIST_HEAD(&server_list[i]);
2975
2976 for (i = 0; i < LP_HASH_SIZE; i++)
2977 INIT_LIST_HEAD(&local_ports[i]);
2978
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002979 down_write(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002980 if (!routing_table_inited) {
2981 init_routing_table();
2982 rt_entry = alloc_routing_table_entry(IPC_ROUTER_NID_LOCAL);
2983 add_routing_table_entry(rt_entry);
2984 routing_table_inited = 1;
2985 }
Karthikeyan Ramasubramaniand06fe072013-05-21 11:49:21 -06002986 up_write(&routing_table_lock_lha3);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002987
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002988 ret = msm_ipc_router_init_sockets();
2989 if (ret < 0)
2990 pr_err("%s: Init sockets failed\n", __func__);
2991
Karthikeyan Ramasubramanian1668cc62012-09-23 22:23:36 -06002992 ret = msm_ipc_router_security_init();
2993 if (ret < 0)
2994 pr_err("%s: Security Init failed\n", __func__);
2995
Karthikeyan Ramasubramanian4af9f7c2011-09-30 15:55:18 -06002996 complete_all(&msm_ipc_local_router_up);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002997 return ret;
2998}
2999
3000module_init(msm_ipc_router_init);
3001MODULE_DESCRIPTION("MSM IPC Router");
3002MODULE_LICENSE("GPL v2");