• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * @file Header file describing the flow rings DHD interfaces.
3  *
4  * Flow rings are transmit traffic (=propagating towards antenna) related
5  * entities.
6  *
7  * Provides type definitions and function prototypes used to create, delete and
8  * manage flow rings at 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
22  * of the license of that module.  An independent module is a module which is
23  * not 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] ^           \
76       ((uint8)(prio))) %                                                       \
77      DHD_FLOWRING_HASH_SIZE)
78 
79 #define DHD_IF_ROLE(pub, idx)                                                  \
80     (((if_flow_lkup_t *)(pub)->if_flow_lkup)[idx].role)
81 #define DHD_IF_ROLE_AP(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_AP)
82 #define DHD_IF_ROLE_STA(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_STA)
83 #define DHD_IF_ROLE_P2PGC(pub, idx)                                            \
84     (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_P2P_CLIENT)
85 #define DHD_IF_ROLE_P2PGO(pub, idx)                                            \
86     (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_P2P_GO)
87 #define DHD_IF_ROLE_WDS(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_WDS)
88 #define DHD_IF_ROLE_IBSS(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_IBSS)
89 #ifdef WL_NAN
90 #define DHD_IF_ROLE_NAN(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_NAN)
91 #else
92 #define DHD_IF_ROLE_NAN(pub, idx) (FALSE)
93 #endif /* WL_NAN */
94 #define DHD_IF_ROLE_AWDL(pub, idx) (FALSE)
95 
96 #define DHD_IF_ROLE_GENERIC_STA(pub, idx)                                      \
97     (DHD_IF_ROLE_STA(pub, idx) || DHD_IF_ROLE_P2PGC(pub, idx) ||               \
98      DHD_IF_ROLE_WDS(pub, idx))
99 
100 #define DHD_IF_ROLE_MULTI_CLIENT(pub, idx)                                     \
101     (DHD_IF_ROLE_AP(pub, idx) || DHD_IF_ROLE_P2PGO(pub, idx) ||                \
102      DHD_IF_ROLE_AWDL(pub, idx) || DHD_IF_ROLE_NAN(pub, idx))
103 
104 #define DHD_FLOW_RING(dhdp, flowid)                                            \
105     (flow_ring_node_t *)&(                                                     \
106         ((flow_ring_node_t *)((dhdp)->flow_ring_table))[flowid])
107 
108 struct flow_queue;
109 
110 /* Flow Ring Queue Enqueue overflow callback */
111 typedef int (*flow_queue_cb_t)(struct flow_queue *queue, void *pkt);
112 
113 /**
114  * Each flow ring has an associated (tx flow controlled) queue. 802.3 packets
115  * are transferred between queue and ring. A packet from the host stack is first
116  * added to the queue, and in a later stage transferred to the flow ring.
117  * Packets in the queue are dhd owned, whereas packets in the flow ring are
118  * device owned.
119  */
120 typedef struct flow_queue {
121     dll_t list;         /* manage a flowring queue in a double linked list */
122     void *head;         /* first packet in the queue */
123     void *tail;         /* last packet in the queue */
124     uint16 len;         /* number of packets in the queue */
125     uint16 max;         /* maximum or min budget (used in cumm) */
126     uint32 threshold;   /* parent's cummulative length threshold */
127     void *clen_ptr;     /* parent's cummulative length counter */
128     uint32 failures;    /* enqueue failures due to queue overflow */
129     flow_queue_cb_t cb; /* callback invoked on threshold crossing */
130     uint32
131         l2threshold;  /* grandparent's (level 2) cummulative length threshold */
132     void *l2clen_ptr; /* grandparent's (level 2) cummulative length counter */
133 } flow_queue_t;
134 
135 #define DHD_FLOW_QUEUE_LEN(queue) ((int)(queue)->len)
136 #define DHD_FLOW_QUEUE_MAX(queue) ((int)(queue)->max)
137 #define DHD_FLOW_QUEUE_THRESHOLD(queue) ((int)(queue)->threshold)
138 #define DHD_FLOW_QUEUE_L2THRESHOLD(queue) ((int)(queue)->l2threshold)
139 #define DHD_FLOW_QUEUE_EMPTY(queue) ((queue)->len == 0)
140 #define DHD_FLOW_QUEUE_FAILURES(queue) ((queue)->failures)
141 
142 #define DHD_FLOW_QUEUE_AVAIL(queue) ((int)((queue)->max - (queue)->len))
143 #define DHD_FLOW_QUEUE_FULL(queue) ((queue)->len >= (queue)->max)
144 
145 #define DHD_FLOW_QUEUE_OVFL(queue, budget) (((queue)->len) > budget)
146 
147 #define DHD_FLOW_QUEUE_SET_MAX(queue, budget) ((queue)->max) = ((budget)-1)
148 
149 /* Queue's cummulative threshold. */
150 #define DHD_FLOW_QUEUE_SET_THRESHOLD(queue, cumm_threshold)                    \
151     ((queue)->threshold) = ((cumm_threshold)-1)
152 
153 /* Queue's cummulative length object accessor. */
154 #define DHD_FLOW_QUEUE_CLEN_PTR(queue) ((queue)->clen_ptr)
155 
156 /* Set a queue's cumm_len point to a parent's cumm_ctr_t cummulative length */
157 #define DHD_FLOW_QUEUE_SET_CLEN(queue, parent_clen_ptr)                        \
158     ((queue)->clen_ptr) = (void *)(parent_clen_ptr)
159 
160 /* Queue's level 2 cummulative threshold. */
161 #define DHD_FLOW_QUEUE_SET_L2THRESHOLD(queue, l2cumm_threshold)                \
162     ((queue)->l2threshold) = ((l2cumm_threshold)-1)
163 
164 /* Queue's level 2 cummulative length object accessor. */
165 #define DHD_FLOW_QUEUE_L2CLEN_PTR(queue) ((queue)->l2clen_ptr)
166 
167 /* Set a queue's level 2 cumm_len point to a grandparent's cumm_ctr_t
168  * cummulative length */
169 #define DHD_FLOW_QUEUE_SET_L2CLEN(queue, grandparent_clen_ptr)                 \
170     ((queue)->l2clen_ptr) = (void *)(grandparent_clen_ptr)
171 
172 #define DHD_FLOWRING_TXSTATUS_CNT_UPDATE(bus, flowid, txstatus)
173 
174 /* Pkttag not compatible with PROP_TXSTATUS or WLFC */
175 typedef struct dhd_pkttag_fr {
176     uint16 flowid;
177     uint16 ifid;
178 #ifdef DHD_LB_TXC
179     int dataoff;
180     dmaaddr_t physaddr;
181     uint32 pa_len;
182 #endif /* DHD_LB_TXC */
183 } dhd_pkttag_fr_t;
184 
185 #define DHD_PKTTAG_SET_IFID(tag, idx) ((tag)->ifid = (uint16)(idx))
186 #define DHD_PKTTAG_SET_PA(tag, pa) ((tag)->physaddr = (pa))
187 #define DHD_PKTTAG_SET_PA_LEN(tag, palen) ((tag)->pa_len = (palen))
188 #define DHD_PKTTAG_IFID(tag) ((tag)->ifid)
189 #define DHD_PKTTAG_PA(tag) ((tag)->physaddr)
190 #define DHD_PKTTAG_PA_LEN(tag) ((tag)->pa_len)
191 
192 /** each flow ring is dedicated to a tid/sa/da combination */
193 typedef struct flow_info {
194     uint8 tid;
195     uint8 ifindex;
196     uchar sa[ETHER_ADDR_LEN];
197     uchar da[ETHER_ADDR_LEN];
198 #ifdef TX_STATUS_LATENCY_STATS
199     /* total number of tx_status received on this flowid */
200     uint64 num_tx_status;
201     /* cumulative tx_status latency for this flowid */
202     uint64 cum_tx_status_latency;
203     /* num tx packets sent on this flowring */
204     uint64 num_tx_pkts;
205 #endif /* TX_STATUS_LATENCY_STATS */
206 } flow_info_t;
207 
208 /** a flow ring is used for outbound (towards antenna) 802.3 packets */
209 typedef struct flow_ring_node {
210     dll_t list; /* manage a constructed flowring in a dll, must be at first
211                    place */
212     flow_queue_t queue; /* queues packets before they enter the flow ring, flow
213                            control */
214     bool active;
215     uint8 status;
216     /*
217      * flowid: unique ID of a flow ring, which can either be unicast or
218      * broadcast/multicast. For unicast flow rings, the flow id accelerates ARM
219      * 802.3->802.11 header translation.
220      */
221     uint16 flowid;
222     flow_info_t flow_info;
223     void *prot_info;
224     void *lock; /* lock for flowring access protection */
225 
226 #ifdef IDLE_TX_FLOW_MGMT
227     uint64 last_active_ts; /* contains last active timestamp */
228 #endif                     /* IDLE_TX_FLOW_MGMT */
229 #ifdef DHD_HP2P
230     bool hp2p_ring;
231 #endif /* DHD_HP2P */
232 } flow_ring_node_t;
233 
234 typedef flow_ring_node_t flow_ring_table_t;
235 
236 typedef struct flow_hash_info {
237     uint16 flowid;
238     flow_info_t flow_info;
239     struct flow_hash_info *next;
240 } flow_hash_info_t;
241 
242 typedef struct if_flow_lkup {
243     bool status;
244     uint8 role; /* Interface role: STA/AP */
245     flow_hash_info_t *fl_hash[DHD_FLOWRING_HASH_SIZE]; /* Lkup Hash table */
246 } if_flow_lkup_t;
247 
dhd_constlist_to_flowring(dll_t * item)248 static INLINE flow_ring_node_t *dhd_constlist_to_flowring(dll_t *item)
249 {
250     return ((flow_ring_node_t *)item);
251 }
252 
253 /* Exported API */
254 
255 /* Flow ring's queue management functions */
256 extern flow_ring_node_t *dhd_flow_ring_node(dhd_pub_t *dhdp, uint16 flowid);
257 extern flow_queue_t *dhd_flow_queue(dhd_pub_t *dhdp, uint16 flowid);
258 
259 extern void dhd_flow_queue_init(dhd_pub_t *dhdp, flow_queue_t *queue, int max);
260 extern void dhd_flow_queue_reinit(dhd_pub_t *dhdp, flow_queue_t *queue,
261                                   int max);
262 extern void dhd_flow_queue_register(flow_queue_t *queue, flow_queue_cb_t cb);
263 extern int dhd_flow_queue_enqueue(dhd_pub_t *dhdp, flow_queue_t *queue,
264                                   void *pkt);
265 extern void *dhd_flow_queue_dequeue(dhd_pub_t *dhdp, flow_queue_t *queue);
266 extern void dhd_flow_queue_reinsert(dhd_pub_t *dhdp, flow_queue_t *queue,
267                                     void *pkt);
268 
269 extern void dhd_flow_ring_config_thresholds(dhd_pub_t *dhdp, uint16 flowid,
270                                             int queue_budget,
271                                             int cumm_threshold, void *cumm_ctr,
272                                             int l2cumm_threshold,
273                                             void *l2cumm_ctr);
274 extern int dhd_flow_rings_init(dhd_pub_t *dhdp, uint32 num_flow_rings);
275 
276 extern void dhd_flow_rings_deinit(dhd_pub_t *dhdp);
277 
278 extern int dhd_flowid_update(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio,
279                              void *pktbuf);
280 extern int dhd_flowid_debug_create(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio,
281                                    char *sa, char *da, uint16 *flowid);
282 extern int dhd_flowid_find_by_ifidx(dhd_pub_t *dhdp, uint8 ifidex,
283                                     uint16 flowid);
284 
285 extern void dhd_flowid_free(dhd_pub_t *dhdp, uint8 ifindex, uint16 flowid);
286 
287 extern void dhd_flow_rings_delete(dhd_pub_t *dhdp, uint8 ifindex);
288 extern void dhd_flow_rings_flush(dhd_pub_t *dhdp, uint8 ifindex);
289 
290 extern void dhd_flow_rings_delete_for_peer(dhd_pub_t *dhdp, uint8 ifindex,
291                                            char *addr);
292 
293 /* Handle Interface ADD, DEL operations */
294 extern void dhd_update_interface_flow_info(dhd_pub_t *dhdp, uint8 ifindex,
295                                            uint8 op, uint8 role);
296 
297 /* Handle a STA interface link status update */
298 extern int dhd_update_interface_link_status(dhd_pub_t *dhdp, uint8 ifindex,
299                                             uint8 status);
300 extern int dhd_flow_prio_map(dhd_pub_t *dhd, uint8 *map, bool set);
301 extern int dhd_update_flow_prio_map(dhd_pub_t *dhdp, uint8 map);
302 
303 extern uint8 dhd_flow_rings_ifindex2role(dhd_pub_t *dhdp, uint8 ifindex);
304 #endif /* _dhd_flowrings_h_ */
305