1 /*
2  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: qdf_pkt_add_timestamp.h
21  * This file defines HLOS agnostic functions providing external interface
22  * for adding timestamp in packet payload.
23  */
24 
25 #if  !defined(_QDF_PKT_ADD_TS_H)
26 #define _QDF_PKT_ADD_TS_H
27 
28 #include  <qdf_nbuf.h>
29 #include  <qdf_types.h>
30 #include  <qdf_trace.h>
31 
32 /**
33  * enum qdf_pkt_supported_proto - supported protocol for timestamp
34  * @QDF_PKT_PROTO_INVAL: invalid
35  * @QDF_PKT_PROTO_TCP: tcp protocol
36  * @QDF_PKT_PROTO_UDP: udp protocol
37  * @QDF_PKT_PROTO_MAX: max, keep it at last
38  */
39 enum qdf_pkt_supported_proto {
40 	QDF_PKT_PROTO_INVAL,
41 	QDF_PKT_PROTO_TCP,
42 	QDF_PKT_PROTO_UDP,
43 	QDF_PKT_PROTO_MAX
44 };
45 
46 /**
47  * enum qdf_pkt_timestamp_index - index of different timestamp
48  * @QDF_PKT_TX_DRIVER_ENTRY: tx driver entry timestamp
49  * @QDF_PKT_TX_DRIVER_EXIT: tx driver exit timestamp
50  * @QDF_PKT_RX_DRIVER_ENTRY: rx driver entry timestamp
51  * @QDF_PKT_RX_DRIVER_EXIT: rx driver exit timestamp
52  * @QDF_PKT_TIMESTAMP_MAX: maximum index, keep it at last
53  */
54 enum qdf_pkt_timestamp_index {
55 	QDF_PKT_TX_DRIVER_ENTRY,
56 	QDF_PKT_TX_DRIVER_EXIT,
57 	QDF_PKT_RX_DRIVER_ENTRY,
58 	QDF_PKT_RX_DRIVER_EXIT,
59 	QDF_PKT_TIMESTAMP_MAX
60 };
61 
62 #ifdef CONFIG_DP_PKT_ADD_TIMESTAMP
63 
64 #define NUM_DP_PKT_TIMESTAMP_SUPPORT 4
65 
66 struct ts_info {
67 	uint64_t sec;
68 	uint64_t usec;
69 } qdf_packed;
70 
71 struct ts {
72 	struct ts_info ts_info[QDF_PKT_TIMESTAMP_MAX];
73 } qdf_packed;
74 
75 #define QDF_PKT_PROTO_TCP_BIT	(1 << QDF_PKT_PROTO_TCP)
76 #define QDF_PKT_PROTO_UDP_BIT	(1 << QDF_PKT_PROTO_UDP)
77 
78 struct dp_pkt_proto_info {
79 	enum qdf_pkt_supported_proto proto;
80 	uint16_t port;
81 	uint16_t offset;
82 };
83 
84 struct dp_pkt_add_ts_info {
85 	uint8_t current_index;
86 	uint16_t enable_protocol_bitmap;
87 	struct dp_pkt_proto_info proto_info[NUM_DP_PKT_TIMESTAMP_SUPPORT];
88 };
89 
90 /**
91  * qdf_set_dp_pkt_add_ts_info() - set protocol/port and offset info
92  *
93  * @proto: protocol to timestamp
94  * @port: destination port of protocol
95  * @offset: offset in payload
96  *
97  * Return: 0 for success
98  */
99 int qdf_set_dp_pkt_add_ts_info(enum qdf_pkt_supported_proto proto,
100 			       uint16_t port, uint16_t offset);
101 
102 /**
103  * qdf_clear_dp_pkt_add_ts_info() - clear all timestamp info
104  *
105  * Return: none
106  */
107 void qdf_clear_dp_pkt_add_ts_info(void);
108 
109 /**
110  * qdf_show_dp_pkt_add_ts_info() - Update buffer with configured information
111  *
112  * @buf: buffer pointer to get information
113  * @size: size of the buffer
114  *
115  * Return: number of bytes update in buffer
116  */
117 int qdf_show_dp_pkt_add_ts_info(char *buf, size_t size);
118 
119 /**
120  * qdf_add_dp_pkt_timestamp() - add timestamp in data payload
121  *
122  * @nbuf: network buffer
123  * @index: this decides offset in payload
124  * @time: timestamp to update
125  *
126  * Return: none
127  */
128 void qdf_add_dp_pkt_timestamp(qdf_nbuf_t nbuf,
129 			      enum qdf_pkt_timestamp_index index,
130 			      uint64_t time);
131 
132 /**
133  * qdf_is_dp_pkt_timestamp_enabled() - check if packet timestamping is enabled
134  *
135  * Return: true/false
136  */
137 bool qdf_is_dp_pkt_timestamp_enabled(void);
138 #else
139 
140 static inline
qdf_set_dp_pkt_add_ts_info(enum qdf_pkt_supported_proto proto,uint16_t port,uint16_t offset)141 int qdf_set_dp_pkt_add_ts_info(enum qdf_pkt_supported_proto proto,
142 			       uint16_t port, uint16_t offset)
143 {
144 	return 0;
145 }
146 
147 static inline
qdf_clear_dp_pkt_add_ts_info(void)148 void qdf_clear_dp_pkt_add_ts_info(void)
149 {
150 }
151 
152 static inline
qdf_show_dp_pkt_add_ts_info(char * buf,size_t size)153 int qdf_show_dp_pkt_add_ts_info(char *buf, size_t size)
154 {
155 	return 0;
156 }
157 
158 static inline
qdf_add_dp_pkt_timestamp(qdf_nbuf_t nbuf,enum qdf_pkt_timestamp_index index,uint64_t time)159 void qdf_add_dp_pkt_timestamp(qdf_nbuf_t nbuf,
160 			      enum qdf_pkt_timestamp_index index, uint64_t time)
161 {
162 }
163 
164 static inline
qdf_is_dp_pkt_timestamp_enabled(void)165 bool qdf_is_dp_pkt_timestamp_enabled(void)
166 {
167 	return false;
168 }
169 
170 #endif
171 #endif
172