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