adt3-S dhd_driver source code [1/1]
[GitHub/LineageOS/G12/android_hardware_amlogic_kernel-modules_dhd-driver.git] / bcmdhd.1.579.77.41.1.cn / dhd_flowring.h
1 /*
2 * @file Header file describing the flow rings DHD interfaces.
3 *
4 * Flow rings are transmit traffic (=propagating towards antenna) related entities.
5 *
6 * Provides type definitions and function prototypes used to create, delete and manage flow rings at
7 * high level.
8 *
9 * Copyright (C) 1999-2017, Broadcom Corporation
10 *
11 * Unless you and Broadcom execute a separate written software license
12 * agreement governing use of this software, this software is licensed to you
13 * under the terms of the GNU General Public License version 2 (the "GPL"),
14 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
15 * following added to such license:
16 *
17 * As a special exception, the copyright holders of this software give you
18 * permission to link this software with independent modules, and to copy and
19 * distribute the resulting executable under terms of your choice, provided that
20 * you also meet, for each linked independent module, the terms and conditions of
21 * the license of that module. An independent module is a module which is not
22 * derived from this software. The special exception does not apply to any
23 * modifications of the software.
24 *
25 * Notwithstanding the above, under no circumstances may you combine this
26 * software in any way with any other Broadcom software provided under a license
27 * other than the GPL, without Broadcom's express prior written consent.
28 *
29 *
30 * <<Broadcom-WL-IPTag/Open:>>
31 *
32 * $Id: dhd_flowring.h 672438 2016-11-28 12:35:24Z $
33 */
34
35
36 /****************
37 * Common types *
38 */
39
40 #ifndef _dhd_flowrings_h_
41 #define _dhd_flowrings_h_
42
43 /* Max pkts held in a flow ring's backup queue */
44 #define FLOW_RING_QUEUE_THRESHOLD (2048)
45
46 /* Number of H2D common rings */
47 #define FLOW_RING_COMMON BCMPCIE_H2D_COMMON_MSGRINGS
48
49 #define FLOWID_INVALID (ID16_INVALID)
50 #define FLOWID_RESERVED (FLOW_RING_COMMON)
51
52 #define FLOW_RING_STATUS_OPEN 0
53 #define FLOW_RING_STATUS_CREATE_PENDING 1
54 #define FLOW_RING_STATUS_CLOSED 2
55 #define FLOW_RING_STATUS_DELETE_PENDING 3
56 #define FLOW_RING_STATUS_FLUSH_PENDING 4
57
58 #ifdef IDLE_TX_FLOW_MGMT
59 #define FLOW_RING_STATUS_SUSPENDED 5
60 #define FLOW_RING_STATUS_RESUME_PENDING 6
61 #endif /* IDLE_TX_FLOW_MGMT */
62 #define FLOW_RING_STATUS_STA_FREEING 7
63
64 #ifdef DHD_EFI
65 #define DHD_FLOWRING_RX_BUFPOST_PKTSZ 1600
66 #else
67 #define DHD_FLOWRING_RX_BUFPOST_PKTSZ 2048
68 #endif
69
70 #define DHD_FLOW_PRIO_AC_MAP 0
71 #define DHD_FLOW_PRIO_TID_MAP 1
72 /* Flow ring prority map for lossless roaming */
73 #define DHD_FLOW_PRIO_LLR_MAP 2
74
75 /* Hashing a MacAddress for lkup into a per interface flow hash table */
76 #define DHD_FLOWRING_HASH_SIZE 256
77 #define DHD_FLOWRING_HASHINDEX(ea, prio) \
78 ((((uint8 *)(ea))[3] ^ ((uint8 *)(ea))[4] ^ ((uint8 *)(ea))[5] ^ ((uint8)(prio))) \
79 % DHD_FLOWRING_HASH_SIZE)
80
81 #define DHD_IF_ROLE(pub, idx) (((if_flow_lkup_t *)(pub)->if_flow_lkup)[idx].role)
82 #define DHD_IF_ROLE_AP(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_AP)
83 #define DHD_IF_ROLE_STA(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_STA)
84 #define DHD_IF_ROLE_P2PGO(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_P2P_GO)
85 #define DHD_IF_ROLE_WDS(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_WDS)
86 #define DHD_FLOW_RING(dhdp, flowid) \
87 (flow_ring_node_t *)&(((flow_ring_node_t *)((dhdp)->flow_ring_table))[flowid])
88
89 struct flow_queue;
90
91 /* Flow Ring Queue Enqueue overflow callback */
92 typedef int (*flow_queue_cb_t)(struct flow_queue * queue, void * pkt);
93
94 /**
95 * Each flow ring has an associated (tx flow controlled) queue. 802.3 packets are transferred
96 * between queue and ring. A packet from the host stack is first added to the queue, and in a later
97 * stage transferred to the flow ring. Packets in the queue are dhd owned, whereas packets in the
98 * flow ring are device owned.
99 */
100 typedef struct flow_queue {
101 dll_t list; /* manage a flowring queue in a double linked list */
102 void * head; /* first packet in the queue */
103 void * tail; /* last packet in the queue */
104 uint16 len; /* number of packets in the queue */
105 uint16 max; /* maximum or min budget (used in cumm) */
106 uint32 threshold; /* parent's cummulative length threshold */
107 void * clen_ptr; /* parent's cummulative length counter */
108 uint32 failures; /* enqueue failures due to queue overflow */
109 flow_queue_cb_t cb; /* callback invoked on threshold crossing */
110 uint32 l2threshold; /* grandparent's (level 2) cummulative length threshold */
111 void * l2clen_ptr; /* grandparent's (level 2) cummulative length counter */
112 } flow_queue_t;
113
114 #define DHD_FLOW_QUEUE_LEN(queue) ((int)(queue)->len)
115 #define DHD_FLOW_QUEUE_MAX(queue) ((int)(queue)->max)
116 #define DHD_FLOW_QUEUE_THRESHOLD(queue) ((int)(queue)->threshold)
117 #define DHD_FLOW_QUEUE_L2THRESHOLD(queue) ((int)(queue)->l2threshold)
118 #define DHD_FLOW_QUEUE_EMPTY(queue) ((queue)->len == 0)
119 #define DHD_FLOW_QUEUE_FAILURES(queue) ((queue)->failures)
120
121 #define DHD_FLOW_QUEUE_AVAIL(queue) ((int)((queue)->max - (queue)->len))
122 #define DHD_FLOW_QUEUE_FULL(queue) ((queue)->len >= (queue)->max)
123
124 #define DHD_FLOW_QUEUE_OVFL(queue, budget) \
125 (((queue)->len) > budget)
126
127 #define DHD_FLOW_QUEUE_SET_MAX(queue, budget) \
128 ((queue)->max) = ((budget) - 1)
129
130 /* Queue's cummulative threshold. */
131 #define DHD_FLOW_QUEUE_SET_THRESHOLD(queue, cumm_threshold) \
132 ((queue)->threshold) = ((cumm_threshold) - 1)
133
134 /* Queue's cummulative length object accessor. */
135 #define DHD_FLOW_QUEUE_CLEN_PTR(queue) ((queue)->clen_ptr)
136
137 /* Set a queue's cumm_len point to a parent's cumm_ctr_t cummulative length */
138 #define DHD_FLOW_QUEUE_SET_CLEN(queue, parent_clen_ptr) \
139 ((queue)->clen_ptr) = (void *)(parent_clen_ptr)
140
141 /* Queue's level 2 cummulative threshold. */
142 #define DHD_FLOW_QUEUE_SET_L2THRESHOLD(queue, l2cumm_threshold) \
143 ((queue)->l2threshold) = ((l2cumm_threshold) - 1)
144
145 /* Queue's level 2 cummulative length object accessor. */
146 #define DHD_FLOW_QUEUE_L2CLEN_PTR(queue) ((queue)->l2clen_ptr)
147
148 /* Set a queue's level 2 cumm_len point to a grandparent's cumm_ctr_t cummulative length */
149 #define DHD_FLOW_QUEUE_SET_L2CLEN(queue, grandparent_clen_ptr) \
150 ((queue)->l2clen_ptr) = (void *)(grandparent_clen_ptr)
151
152 /* see wlfc_proto.h for tx status details */
153 #define DHD_FLOWRING_MAXSTATUS_MSGS 5
154 #define DHD_FLOWRING_TXSTATUS_CNT_UPDATE(bus, flowid, txstatus)
155
156 /* Pkttag not compatible with PROP_TXSTATUS or WLFC */
157 typedef struct dhd_pkttag_fr {
158 uint16 flowid;
159 uint16 ifid;
160 int dataoff;
161 dmaaddr_t physaddr;
162 uint32 pa_len;
163 } dhd_pkttag_fr_t;
164
165 #define DHD_PKTTAG_SET_IFID(tag, idx) ((tag)->ifid = (uint16)(idx))
166 #define DHD_PKTTAG_SET_PA(tag, pa) ((tag)->physaddr = (pa))
167 #define DHD_PKTTAG_SET_PA_LEN(tag, palen) ((tag)->pa_len = (palen))
168 #define DHD_PKTTAG_IFID(tag) ((tag)->ifid)
169 #define DHD_PKTTAG_PA(tag) ((tag)->physaddr)
170 #define DHD_PKTTAG_PA_LEN(tag) ((tag)->pa_len)
171
172
173 /** each flow ring is dedicated to a tid/sa/da combination */
174 typedef struct flow_info {
175 uint8 tid;
176 uint8 ifindex;
177 char sa[ETHER_ADDR_LEN];
178 char da[ETHER_ADDR_LEN];
179 } flow_info_t;
180
181 /** a flow ring is used for outbound (towards antenna) 802.3 packets */
182 typedef struct flow_ring_node {
183 dll_t list; /* manage a constructed flowring in a dll, must be at first place */
184 flow_queue_t queue; /* queues packets before they enter the flow ring, flow control */
185 bool active;
186 uint8 status;
187 /*
188 * flowid: unique ID of a flow ring, which can either be unicast or broadcast/multicast. For
189 * unicast flow rings, the flow id accelerates ARM 802.3->802.11 header translation.
190 */
191 uint16 flowid;
192 flow_info_t flow_info;
193 void *prot_info;
194 void *lock; /* lock for flowring access protection */
195
196 #ifdef IDLE_TX_FLOW_MGMT
197 uint64 last_active_ts; /* contains last active timestamp */
198 #endif /* IDLE_TX_FLOW_MGMT */
199 #ifdef DEVICE_TX_STUCK_DETECT
200 /* Time stamp(msec) when last time a Tx packet completion is received on this flow ring */
201 uint32 tx_cmpl;
202 /*
203 * Holds the tx_cmpl which was read during the previous
204 * iteration of the stuck detection algo
205 */
206 uint32 tx_cmpl_prev;
207 /* counter to decide if this particlur flow is stuck or not */
208 uint32 stuck_count;
209 #endif /* DEVICE_TX_STUCK_DETECT */
210
211 } flow_ring_node_t;
212
213 typedef flow_ring_node_t flow_ring_table_t;
214
215 typedef struct flow_hash_info {
216 uint16 flowid;
217 flow_info_t flow_info;
218 struct flow_hash_info *next;
219 } flow_hash_info_t;
220
221 typedef struct if_flow_lkup {
222 bool status;
223 uint8 role; /* Interface role: STA/AP */
224 flow_hash_info_t *fl_hash[DHD_FLOWRING_HASH_SIZE]; /* Lkup Hash table */
225 } if_flow_lkup_t;
226
227 static INLINE flow_ring_node_t *
228 dhd_constlist_to_flowring(dll_t *item)
229 {
230 return ((flow_ring_node_t *)item);
231 }
232
233 /* Exported API */
234
235 /* Flow ring's queue management functions */
236 extern flow_ring_node_t * dhd_flow_ring_node(dhd_pub_t *dhdp, uint16 flowid);
237 extern flow_queue_t * dhd_flow_queue(dhd_pub_t *dhdp, uint16 flowid);
238
239 extern void dhd_flow_queue_init(dhd_pub_t *dhdp, flow_queue_t *queue, int max);
240 extern void dhd_flow_queue_reinit(dhd_pub_t *dhdp, flow_queue_t *queue, int max);
241 extern void dhd_flow_queue_register(flow_queue_t *queue, flow_queue_cb_t cb);
242 extern int dhd_flow_queue_enqueue(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt);
243 extern void * dhd_flow_queue_dequeue(dhd_pub_t *dhdp, flow_queue_t *queue);
244 extern void dhd_flow_queue_reinsert(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt);
245
246 extern void dhd_flow_ring_config_thresholds(dhd_pub_t *dhdp, uint16 flowid,
247 int queue_budget, int cumm_threshold, void *cumm_ctr,
248 int l2cumm_threshold, void *l2cumm_ctr);
249 extern int dhd_flow_rings_init(dhd_pub_t *dhdp, uint32 num_flow_rings);
250
251 extern void dhd_flow_rings_deinit(dhd_pub_t *dhdp);
252
253 extern int dhd_flowid_update(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio,
254 void *pktbuf);
255
256 extern void dhd_flowid_free(dhd_pub_t *dhdp, uint8 ifindex, uint16 flowid);
257
258 extern void dhd_flow_rings_delete(dhd_pub_t *dhdp, uint8 ifindex);
259 extern void dhd_flow_rings_flush(dhd_pub_t *dhdp, uint8 ifindex);
260
261 extern void dhd_flow_rings_delete_for_peer(dhd_pub_t *dhdp, uint8 ifindex,
262 char *addr);
263
264 /* Handle Interface ADD, DEL operations */
265 extern void dhd_update_interface_flow_info(dhd_pub_t *dhdp, uint8 ifindex,
266 uint8 op, uint8 role);
267
268 /* Handle a STA interface link status update */
269 extern int dhd_update_interface_link_status(dhd_pub_t *dhdp, uint8 ifindex,
270 uint8 status);
271 extern int dhd_flow_prio_map(dhd_pub_t *dhd, uint8 *map, bool set);
272 extern int dhd_update_flow_prio_map(dhd_pub_t *dhdp, uint8 map);
273
274 extern uint8 dhd_flow_rings_ifindex2role(dhd_pub_t *dhdp, uint8 ifindex);
275 #endif /* _dhd_flowrings_h_ */