blob: e33a10a6cbd48b624c8c5556818fdf5fd7123a8f [file] [log] [blame]
Karthikeyan Ramasubramanian6a116d62016-09-16 16:05:32 -06001/* Copyright (c) 2011-2016, 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
13#ifndef _IPC_ROUTER_XPRT_H
14#define _IPC_ROUTER_XPRT_H
15
16#include <linux/types.h>
17#include <linux/errno.h>
18#include <linux/mm.h>
19#include <linux/list.h>
20#include <linux/platform_device.h>
21#include <linux/msm_ipc.h>
22#include <linux/ipc_router.h>
23#include <linux/kref.h>
24
25#define IPC_ROUTER_XPRT_EVENT_DATA 1
26#define IPC_ROUTER_XPRT_EVENT_OPEN 2
27#define IPC_ROUTER_XPRT_EVENT_CLOSE 3
28
29#define FRAG_PKT_WRITE_ENABLE 0x1
30
31/**
32 * rr_header_v1 - IPC Router header version 1
33 * @version: Version information.
34 * @type: IPC Router Message Type.
35 * @src_node_id: Source Node ID of the message.
36 * @src_port_id: Source Port ID of the message.
37 * @control_flag: Flag to indicate flow control.
38 * @size: Size of the IPC Router payload.
39 * @dst_node_id: Destination Node ID of the message.
40 * @dst_port_id: Destination Port ID of the message.
41 */
42struct rr_header_v1 {
43 uint32_t version;
44 uint32_t type;
45 uint32_t src_node_id;
46 uint32_t src_port_id;
47 uint32_t control_flag;
48 uint32_t size;
49 uint32_t dst_node_id;
50 uint32_t dst_port_id;
51};
52
53/**
54 * rr_header_v2 - IPC Router header version 2
55 * @version: Version information.
56 * @type: IPC Router Message Type.
57 * @control_flag: Flags to indicate flow control, optional header etc.
58 * @opt_len: Combined size of the all optional headers in units of words.
59 * @size: Size of the IPC Router payload.
60 * @src_node_id: Source Node ID of the message.
61 * @src_port_id: Source Port ID of the message.
62 * @dst_node_id: Destination Node ID of the message.
63 * @dst_port_id: Destination Port ID of the message.
64 */
65struct rr_header_v2 {
66 uint8_t version;
67 uint8_t type;
68 uint8_t control_flag;
69 uint8_t opt_len;
70 uint32_t size;
71 uint16_t src_node_id;
72 uint16_t src_port_id;
73 uint16_t dst_node_id;
74 uint16_t dst_port_id;
75} __attribute__((__packed__));
76
77union rr_header {
78 struct rr_header_v1 hdr_v1;
79 struct rr_header_v2 hdr_v2;
80};
81
82/**
83 * rr_opt_hdr - Optional header for IPC Router header version 2
84 * @len: Total length of the optional header.
85 * @data: Pointer to the actual optional header.
86 */
87struct rr_opt_hdr {
88 size_t len;
89 unsigned char *data;
90};
91
92#define IPC_ROUTER_HDR_SIZE sizeof(union rr_header)
93#define IPCR_WORD_SIZE 4
94
95/**
96 * rr_packet - Router to Router packet structure
97 * @list: Pointer to prev & next packets in a port's rx list.
98 * @hdr: Header information extracted from or prepended to a packet.
99 * @opt_hdr: Optinal header information.
100 * @pkt_fragment_q: Queue of SKBs containing payload.
101 * @length: Length of data in the chain of SKBs
102 * @ref: Reference count for the packet.
103 */
104struct rr_packet {
105 struct list_head list;
106 struct rr_header_v1 hdr;
107 struct rr_opt_hdr opt_hdr;
108 struct sk_buff_head *pkt_fragment_q;
109 uint32_t length;
110 struct kref ref;
111};
112
113/**
114 * msm_ipc_router_xprt - Structure to hold XPRT specific information
115 * @name: Name of the XPRT.
116 * @link_id: Network cluster ID to which the XPRT belongs to.
117 * @priv: XPRT's private data.
118 * @get_version: Method to get header version supported by the XPRT.
119 * @set_version: Method to set header version in XPRT.
120 * @get_option: Method to get XPRT specific options.
121 * @read_avail: Method to get data size available to be read from the XPRT.
122 * @read: Method to read data from the XPRT.
123 * @write_avail: Method to get write space available in the XPRT.
124 * @write: Method to write data to the XPRT.
125 * @close: Method to close the XPRT.
126 * @sft_close_done: Method to indicate to the XPRT that handling of reset
127 * event is complete.
128 */
129struct msm_ipc_router_xprt {
130 char *name;
131 uint32_t link_id;
132 void *priv;
133
134 int (*get_version)(struct msm_ipc_router_xprt *xprt);
135 int (*get_option)(struct msm_ipc_router_xprt *xprt);
136 void (*set_version)(struct msm_ipc_router_xprt *xprt,
137 unsigned int version);
138 int (*read_avail)(struct msm_ipc_router_xprt *xprt);
139 int (*read)(void *data, uint32_t len,
140 struct msm_ipc_router_xprt *xprt);
141 int (*write_avail)(struct msm_ipc_router_xprt *xprt);
142 int (*write)(void *data, uint32_t len,
143 struct msm_ipc_router_xprt *xprt);
144 int (*close)(struct msm_ipc_router_xprt *xprt);
145 void (*sft_close_done)(struct msm_ipc_router_xprt *xprt);
146};
147
148void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt,
149 unsigned int event,
150 void *data);
151
152/**
153 * create_pkt() - Create a Router packet
154 * @data: SKB queue to be contained inside the packet.
155 *
156 * @return: pointer to packet on success, NULL on failure.
157 */
158struct rr_packet *create_pkt(struct sk_buff_head *data);
159struct rr_packet *clone_pkt(struct rr_packet *pkt);
160void release_pkt(struct rr_packet *pkt);
161
162/**
163 * ipc_router_peek_pkt_size() - Peek into the packet header to get potential
164 * packet size
165 * @data: Starting address of the packet which points to router header.
166 *
167 * @returns: potential packet size on success, < 0 on error.
168 *
169 * This function is used by the underlying transport abstraction layer to
170 * peek into the potential packet size of an incoming packet. This information
171 * is used to perform link layer fragmentation and re-assembly
172 */
173int ipc_router_peek_pkt_size(char *data);
174
175#endif