ipc_router.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef _ARCH_ARM_MACH_MSM_IPC_ROUTER_H
  13. #define _ARCH_ARM_MACH_MSM_IPC_ROUTER_H
  14. #include <linux/types.h>
  15. #include <linux/socket.h>
  16. #include <linux/errno.h>
  17. #include <linux/mm.h>
  18. #include <linux/list.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/msm_ipc.h>
  21. #include <net/sock.h>
  22. /* definitions for the R2R wire protcol */
  23. #define IPC_ROUTER_V1 1
  24. /*
  25. * Ambiguous definition but will enable multiplexing IPC_ROUTER_V2 packets
  26. * with an existing alternate transport in user-space, if needed.
  27. */
  28. #define IPC_ROUTER_V2 3
  29. #define IPC_ROUTER_ADDRESS 0x0000FFFF
  30. #define IPC_ROUTER_NID_LOCAL 1
  31. #define MAX_IPC_PKT_SIZE 66000
  32. #define IPC_ROUTER_CTRL_CMD_DATA 1
  33. #define IPC_ROUTER_CTRL_CMD_HELLO 2
  34. #define IPC_ROUTER_CTRL_CMD_BYE 3
  35. #define IPC_ROUTER_CTRL_CMD_NEW_SERVER 4
  36. #define IPC_ROUTER_CTRL_CMD_REMOVE_SERVER 5
  37. #define IPC_ROUTER_CTRL_CMD_REMOVE_CLIENT 6
  38. #define IPC_ROUTER_CTRL_CMD_RESUME_TX 7
  39. #define IPC_ROUTER_CTRL_CMD_EXIT 8
  40. #define IPC_ROUTER_CTRL_CMD_PING 9
  41. #define IPC_ROUTER_DEFAULT_RX_QUOTA 5
  42. #define IPC_ROUTER_XPRT_EVENT_DATA 1
  43. #define IPC_ROUTER_XPRT_EVENT_OPEN 2
  44. #define IPC_ROUTER_XPRT_EVENT_CLOSE 3
  45. #define IPC_ROUTER_INFINITY -1
  46. #define DEFAULT_RCV_TIMEO 0
  47. #define ALIGN_SIZE(x) ((4 - ((x) & 3)) & 3)
  48. #define ALL_SERVICE 0xFFFFFFFF
  49. #define ALL_INSTANCE 0xFFFFFFFF
  50. #define CONTROL_FLAG_CONFIRM_RX 0x1
  51. #define CONTROL_FLAG_OPT_HDR 0x2
  52. #define FRAG_PKT_WRITE_ENABLE 0x1
  53. enum {
  54. CLIENT_PORT,
  55. SERVER_PORT,
  56. CONTROL_PORT,
  57. IRSC_PORT,
  58. };
  59. enum {
  60. NULL_MODE,
  61. SINGLE_LINK_MODE,
  62. MULTI_LINK_MODE,
  63. };
  64. /**
  65. * rr_control_msg - Control message structure
  66. * @cmd: Command identifier for HELLO message in Version 1.
  67. * @hello: Message structure for HELLO message in Version 2.
  68. * @srv: Message structure for NEW_SERVER/REMOVE_SERVER events.
  69. * @cli: Message structure for REMOVE_CLIENT event.
  70. */
  71. union rr_control_msg {
  72. uint32_t cmd;
  73. struct {
  74. uint32_t cmd;
  75. uint32_t magic;
  76. uint32_t capability;
  77. } hello;
  78. struct {
  79. uint32_t cmd;
  80. uint32_t service;
  81. uint32_t instance;
  82. uint32_t node_id;
  83. uint32_t port_id;
  84. } srv;
  85. struct {
  86. uint32_t cmd;
  87. uint32_t node_id;
  88. uint32_t port_id;
  89. } cli;
  90. };
  91. /**
  92. * rr_header_v1 - IPC Router header version 1
  93. * @version: Version information.
  94. * @type: IPC Router Message Type.
  95. * @src_node_id: Source Node ID of the message.
  96. * @src_port_id: Source Port ID of the message.
  97. * @control_flag: Flag to indicate flow control.
  98. * @size: Size of the IPC Router payload.
  99. * @dst_node_id: Destination Node ID of the message.
  100. * @dst_port_id: Destination Port ID of the message.
  101. */
  102. struct rr_header_v1 {
  103. uint32_t version;
  104. uint32_t type;
  105. uint32_t src_node_id;
  106. uint32_t src_port_id;
  107. uint32_t control_flag;
  108. uint32_t size;
  109. uint32_t dst_node_id;
  110. uint32_t dst_port_id;
  111. };
  112. /**
  113. * rr_header_v2 - IPC Router header version 2
  114. * @version: Version information.
  115. * @type: IPC Router Message Type.
  116. * @control_flag: Flags to indicate flow control, optional header etc.
  117. * @size: Size of the IPC Router payload.
  118. * @src_node_id: Source Node ID of the message.
  119. * @src_port_id: Source Port ID of the message.
  120. * @dst_node_id: Destination Node ID of the message.
  121. * @dst_port_id: Destination Port ID of the message.
  122. */
  123. struct rr_header_v2 {
  124. uint8_t version;
  125. uint8_t type;
  126. uint16_t control_flag;
  127. uint32_t size;
  128. uint16_t src_node_id;
  129. uint16_t src_port_id;
  130. uint16_t dst_node_id;
  131. uint16_t dst_port_id;
  132. } __attribute__((__packed__));
  133. union rr_header {
  134. struct rr_header_v1 hdr_v1;
  135. struct rr_header_v2 hdr_v2;
  136. };
  137. #define IPC_ROUTER_HDR_SIZE sizeof(union rr_header)
  138. /**
  139. * rr_packet - Router to Router packet structure
  140. * @list: Pointer to prev & next packets in a port's rx list.
  141. * @hdr: Header information extracted from or prepended to a packet.
  142. * @pkt_fragment_q: Queue of SKBs containing payload.
  143. * @length: Length of data in the chain of SKBs
  144. */
  145. struct rr_packet {
  146. struct list_head list;
  147. struct rr_header_v1 hdr;
  148. struct sk_buff_head *pkt_fragment_q;
  149. uint32_t length;
  150. };
  151. struct msm_ipc_sock {
  152. struct sock sk;
  153. struct msm_ipc_port *port;
  154. void *default_pil;
  155. };
  156. /**
  157. * msm_ipc_router_xprt - Structure to hold XPRT specific information
  158. * @name: Name of the XPRT.
  159. * @link_id: Network cluster ID to which the XPRT belongs to.
  160. * @priv: XPRT's private data.
  161. * @get_version: Method to get header version supported by the XPRT.
  162. * @get_option: Method to get XPRT specific options.
  163. * @read_avail: Method to get data size available to be read from the XPRT.
  164. * @read: Method to read data from the XPRT.
  165. * @write_avail: Method to get write space available in the XPRT.
  166. * @write: Method to write data to the XPRT.
  167. * @close: Method to close the XPRT.
  168. * @sft_close_done: Method to indicate to the XPRT that handling of reset
  169. * event is complete.
  170. */
  171. struct msm_ipc_router_xprt {
  172. char *name;
  173. uint32_t link_id;
  174. void *priv;
  175. int (*get_version)(struct msm_ipc_router_xprt *xprt);
  176. int (*get_option)(struct msm_ipc_router_xprt *xprt);
  177. int (*read_avail)(struct msm_ipc_router_xprt *xprt);
  178. int (*read)(void *data, uint32_t len,
  179. struct msm_ipc_router_xprt *xprt);
  180. int (*write_avail)(struct msm_ipc_router_xprt *xprt);
  181. int (*write)(void *data, uint32_t len,
  182. struct msm_ipc_router_xprt *xprt);
  183. int (*close)(struct msm_ipc_router_xprt *xprt);
  184. void (*sft_close_done)(struct msm_ipc_router_xprt *xprt);
  185. };
  186. void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt,
  187. unsigned event,
  188. void *data);
  189. struct rr_packet *clone_pkt(struct rr_packet *pkt);
  190. void release_pkt(struct rr_packet *pkt);
  191. struct msm_ipc_port *msm_ipc_router_create_raw_port(void *endpoint,
  192. void (*notify)(unsigned event, void *priv),
  193. void *priv);
  194. int msm_ipc_router_send_to(struct msm_ipc_port *src,
  195. struct sk_buff_head *data,
  196. struct msm_ipc_addr *dest);
  197. int msm_ipc_router_read(struct msm_ipc_port *port_ptr,
  198. struct rr_packet **pkt,
  199. size_t buf_len);
  200. int msm_ipc_router_bind_control_port(struct msm_ipc_port *port_ptr);
  201. int msm_ipc_router_recv_from(struct msm_ipc_port *port_ptr,
  202. struct rr_packet **pkt,
  203. struct msm_ipc_addr *src_addr,
  204. long timeout);
  205. int msm_ipc_router_register_server(struct msm_ipc_port *server_port,
  206. struct msm_ipc_addr *name);
  207. int msm_ipc_router_unregister_server(struct msm_ipc_port *server_port);
  208. int msm_ipc_router_init_sockets(void);
  209. void msm_ipc_router_exit_sockets(void);
  210. void msm_ipc_sync_sec_rule(uint32_t service, uint32_t instance, void *rule);
  211. void msm_ipc_sync_default_sec_rule(void *rule);
  212. int msm_ipc_router_rx_data_wait(struct msm_ipc_port *port_ptr, long timeout);
  213. #if defined CONFIG_MSM_IPC_ROUTER_SMD_XPRT
  214. extern void *msm_ipc_load_default_node(void);
  215. extern void msm_ipc_unload_default_node(void *pil);
  216. #else
  217. static inline void *msm_ipc_load_default_node(void)
  218. { return NULL; }
  219. static inline void msm_ipc_unload_default_node(void *pil) { }
  220. #endif
  221. void msm_ipc_router_free_skb(struct sk_buff_head *skb_head);
  222. #endif