blob: bba7179144b2229f354d2ab189b44719d741d4bd [file] [log] [blame]
Arun Kumar Neelakantam35141a42018-06-18 19:12:17 +05301/* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
Karthikeyan Ramasubramanian6a116d62016-09-16 16:05:32 -06002 *
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.
Arun Kumar Neelakantam74ff8562017-05-26 17:57:52 +0530103 * @ws_need: Flag to check wakeup soruce need
Karthikeyan Ramasubramanian6a116d62016-09-16 16:05:32 -0600104 */
105struct rr_packet {
106 struct list_head list;
107 struct rr_header_v1 hdr;
108 struct rr_opt_hdr opt_hdr;
109 struct sk_buff_head *pkt_fragment_q;
110 uint32_t length;
111 struct kref ref;
Arun Kumar Neelakantam74ff8562017-05-26 17:57:52 +0530112 bool ws_need;
Karthikeyan Ramasubramanian6a116d62016-09-16 16:05:32 -0600113};
114
115/**
116 * msm_ipc_router_xprt - Structure to hold XPRT specific information
117 * @name: Name of the XPRT.
118 * @link_id: Network cluster ID to which the XPRT belongs to.
119 * @priv: XPRT's private data.
120 * @get_version: Method to get header version supported by the XPRT.
121 * @set_version: Method to set header version in XPRT.
122 * @get_option: Method to get XPRT specific options.
123 * @read_avail: Method to get data size available to be read from the XPRT.
124 * @read: Method to read data from the XPRT.
125 * @write_avail: Method to get write space available in the XPRT.
126 * @write: Method to write data to the XPRT.
127 * @close: Method to close the XPRT.
128 * @sft_close_done: Method to indicate to the XPRT that handling of reset
129 * event is complete.
Arun Kumar Neelakantam74ff8562017-05-26 17:57:52 +0530130 * @get_ws_info: Method to get the wakeup soruce inforamtion of the XPRT
Arun Kumar Neelakantam35141a42018-06-18 19:12:17 +0530131 * @get_ws_info: Method to get the latency inforamtion of the XPRT.
Karthikeyan Ramasubramanian6a116d62016-09-16 16:05:32 -0600132 */
133struct msm_ipc_router_xprt {
134 char *name;
135 uint32_t link_id;
136 void *priv;
137
138 int (*get_version)(struct msm_ipc_router_xprt *xprt);
139 int (*get_option)(struct msm_ipc_router_xprt *xprt);
140 void (*set_version)(struct msm_ipc_router_xprt *xprt,
141 unsigned int version);
142 int (*read_avail)(struct msm_ipc_router_xprt *xprt);
143 int (*read)(void *data, uint32_t len,
144 struct msm_ipc_router_xprt *xprt);
145 int (*write_avail)(struct msm_ipc_router_xprt *xprt);
146 int (*write)(void *data, uint32_t len,
147 struct msm_ipc_router_xprt *xprt);
148 int (*close)(struct msm_ipc_router_xprt *xprt);
149 void (*sft_close_done)(struct msm_ipc_router_xprt *xprt);
Arun Kumar Neelakantam74ff8562017-05-26 17:57:52 +0530150 bool (*get_ws_info)(struct msm_ipc_router_xprt *xprt);
Arun Kumar Neelakantam35141a42018-06-18 19:12:17 +0530151 bool (*get_latency_info)(struct msm_ipc_router_xprt *xprt);
Karthikeyan Ramasubramanian6a116d62016-09-16 16:05:32 -0600152};
153
154void msm_ipc_router_xprt_notify(struct msm_ipc_router_xprt *xprt,
155 unsigned int event,
156 void *data);
157
158/**
159 * create_pkt() - Create a Router packet
160 * @data: SKB queue to be contained inside the packet.
161 *
162 * @return: pointer to packet on success, NULL on failure.
163 */
164struct rr_packet *create_pkt(struct sk_buff_head *data);
165struct rr_packet *clone_pkt(struct rr_packet *pkt);
166void release_pkt(struct rr_packet *pkt);
167
168/**
169 * ipc_router_peek_pkt_size() - Peek into the packet header to get potential
170 * packet size
171 * @data: Starting address of the packet which points to router header.
172 *
173 * @returns: potential packet size on success, < 0 on error.
174 *
175 * This function is used by the underlying transport abstraction layer to
176 * peek into the potential packet size of an incoming packet. This information
177 * is used to perform link layer fragmentation and re-assembly
178 */
179int ipc_router_peek_pkt_size(char *data);
180
181#endif