1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * @file Broadcom Dongle Host Driver (DHD), Flow ring specific code at top level
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Flow rings are transmit traffic (=propagating towards antenna) related entities
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Copyright (C) 2020, Broadcom.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * Unless you and Broadcom execute a separate written software license
10*4882a593Smuzhiyun * agreement governing use of this software, this software is licensed to you
11*4882a593Smuzhiyun * under the terms of the GNU General Public License version 2 (the "GPL"),
12*4882a593Smuzhiyun * available at http://www.broadcom.com/licenses/GPLv2.php, with the
13*4882a593Smuzhiyun * following added to such license:
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * As a special exception, the copyright holders of this software give you
16*4882a593Smuzhiyun * permission to link this software with independent modules, and to copy and
17*4882a593Smuzhiyun * distribute the resulting executable under terms of your choice, provided that
18*4882a593Smuzhiyun * you also meet, for each linked independent module, the terms and conditions of
19*4882a593Smuzhiyun * the license of that module. An independent module is a module which is not
20*4882a593Smuzhiyun * derived from this software. The special exception does not apply to any
21*4882a593Smuzhiyun * modifications of the software.
22*4882a593Smuzhiyun *
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * <<Broadcom-WL-IPTag/Open:>>
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun * $Id$
27*4882a593Smuzhiyun */
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun /** XXX Twiki: [PCIeFullDongleArchitecture] */
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #include <typedefs.h>
32*4882a593Smuzhiyun #include <bcmutils.h>
33*4882a593Smuzhiyun #include <bcmendian.h>
34*4882a593Smuzhiyun #include <bcmdevs.h>
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun #include <ethernet.h>
37*4882a593Smuzhiyun #include <bcmevent.h>
38*4882a593Smuzhiyun #include <dngl_stats.h>
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #include <dhd.h>
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun #include <dhd_flowring.h>
43*4882a593Smuzhiyun #include <dhd_bus.h>
44*4882a593Smuzhiyun #include <dhd_proto.h>
45*4882a593Smuzhiyun #include <dhd_dbg.h>
46*4882a593Smuzhiyun #include <802.1d.h>
47*4882a593Smuzhiyun #include <pcie_core.h>
48*4882a593Smuzhiyun #include <bcmmsgbuf.h>
49*4882a593Smuzhiyun #include <dhd_pcie.h>
50*4882a593Smuzhiyun #include <dhd_config.h>
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun static INLINE int dhd_flow_queue_throttle(flow_queue_t *queue);
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun static INLINE uint16 dhd_flowid_find(dhd_pub_t *dhdp, uint8 ifindex,
55*4882a593Smuzhiyun uint8 prio, char *sa, char *da);
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun static INLINE uint16 dhd_flowid_alloc(dhd_pub_t *dhdp, uint8 ifindex,
58*4882a593Smuzhiyun uint8 prio, char *sa, char *da);
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun static INLINE int dhd_flowid_lookup(dhd_pub_t *dhdp, uint8 ifindex,
61*4882a593Smuzhiyun uint8 prio, char *sa, char *da, uint16 *flowid);
62*4882a593Smuzhiyun int dhd_flow_queue_overflow(flow_queue_t *queue, void *pkt);
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun #define FLOW_QUEUE_PKT_NEXT(p) PKTLINK(p)
65*4882a593Smuzhiyun #define FLOW_QUEUE_PKT_SETNEXT(p, x) PKTSETLINK((p), (x))
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun #ifdef DHD_REPLACE_LOG_INFO_TO_TRACE
68*4882a593Smuzhiyun #define DHD_FLOWRING_INFO DHD_TRACE
69*4882a593Smuzhiyun #else
70*4882a593Smuzhiyun #define DHD_FLOWRING_INFO DHD_INFO
71*4882a593Smuzhiyun #endif /* DHD_REPLACE_LOG_INFO_TO_TRACE */
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun const uint8 prio2ac[8] = { 0, 1, 1, 0, 2, 2, 3, 3 };
74*4882a593Smuzhiyun const uint8 prio2tid[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun /** Queue overflow throttle. Return value: TRUE if throttle needs to be applied */
77*4882a593Smuzhiyun static INLINE int
dhd_flow_queue_throttle(flow_queue_t * queue)78*4882a593Smuzhiyun dhd_flow_queue_throttle(flow_queue_t *queue)
79*4882a593Smuzhiyun {
80*4882a593Smuzhiyun #if defined(BCM_ROUTER_DHD)
81*4882a593Smuzhiyun /* Two tests
82*4882a593Smuzhiyun * 1) Test whether overall level 2 (grandparent) cummulative threshold crossed.
83*4882a593Smuzhiyun * 2) Or test whether queue's budget and overall cummulative threshold crossed.
84*4882a593Smuzhiyun */
85*4882a593Smuzhiyun void *gp_clen_ptr = DHD_FLOW_QUEUE_L2CLEN_PTR(queue);
86*4882a593Smuzhiyun void *parent_clen_ptr = DHD_FLOW_QUEUE_CLEN_PTR(queue);
87*4882a593Smuzhiyun int gp_cumm_threshold = DHD_FLOW_QUEUE_L2THRESHOLD(queue);
88*4882a593Smuzhiyun int cumm_threshold = DHD_FLOW_QUEUE_THRESHOLD(queue);
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun int ret = ((DHD_CUMM_CTR_READ(gp_clen_ptr) > gp_cumm_threshold) ||
91*4882a593Smuzhiyun ((DHD_FLOW_QUEUE_OVFL(queue, DHD_FLOW_QUEUE_MAX(queue))) &&
92*4882a593Smuzhiyun (DHD_CUMM_CTR_READ(parent_clen_ptr) > cumm_threshold)));
93*4882a593Smuzhiyun return ret;
94*4882a593Smuzhiyun #else
95*4882a593Smuzhiyun return DHD_FLOW_QUEUE_FULL(queue);
96*4882a593Smuzhiyun #endif /* ! BCM_ROUTER_DHD */
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun int
BCMFASTPATH(dhd_flow_queue_overflow)100*4882a593Smuzhiyun BCMFASTPATH(dhd_flow_queue_overflow)(flow_queue_t *queue, void *pkt)
101*4882a593Smuzhiyun {
102*4882a593Smuzhiyun return BCME_NORESOURCE;
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun /** Returns flow ring given a flowid */
106*4882a593Smuzhiyun flow_ring_node_t *
dhd_flow_ring_node(dhd_pub_t * dhdp,uint16 flowid)107*4882a593Smuzhiyun dhd_flow_ring_node(dhd_pub_t *dhdp, uint16 flowid)
108*4882a593Smuzhiyun {
109*4882a593Smuzhiyun flow_ring_node_t * flow_ring_node;
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun ASSERT(dhdp != (dhd_pub_t*)NULL);
112*4882a593Smuzhiyun ASSERT(flowid <= dhdp->max_tx_flowid);
113*4882a593Smuzhiyun if (flowid > dhdp->max_tx_flowid) {
114*4882a593Smuzhiyun return NULL;
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun flow_ring_node = &(((flow_ring_node_t*)(dhdp->flow_ring_table))[flowid]);
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun ASSERT(flow_ring_node->flowid == flowid);
120*4882a593Smuzhiyun return flow_ring_node;
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun /** Returns 'backup' queue given a flowid */
124*4882a593Smuzhiyun flow_queue_t *
dhd_flow_queue(dhd_pub_t * dhdp,uint16 flowid)125*4882a593Smuzhiyun dhd_flow_queue(dhd_pub_t *dhdp, uint16 flowid)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun flow_ring_node_t * flow_ring_node = NULL;
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun flow_ring_node = dhd_flow_ring_node(dhdp, flowid);
130*4882a593Smuzhiyun if (flow_ring_node)
131*4882a593Smuzhiyun return &flow_ring_node->queue;
132*4882a593Smuzhiyun else
133*4882a593Smuzhiyun return NULL;
134*4882a593Smuzhiyun }
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun /* Flow ring's queue management functions */
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun /** Reinitialize a flow ring's queue. */
139*4882a593Smuzhiyun void
dhd_flow_queue_reinit(dhd_pub_t * dhdp,flow_queue_t * queue,int max)140*4882a593Smuzhiyun dhd_flow_queue_reinit(dhd_pub_t *dhdp, flow_queue_t *queue, int max)
141*4882a593Smuzhiyun {
142*4882a593Smuzhiyun ASSERT((queue != NULL) && (max > 0));
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun queue->head = queue->tail = NULL;
145*4882a593Smuzhiyun queue->len = 0;
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun /* Set queue's threshold and queue's parent cummulative length counter */
148*4882a593Smuzhiyun ASSERT(max > 1);
149*4882a593Smuzhiyun DHD_FLOW_QUEUE_SET_MAX(queue, max);
150*4882a593Smuzhiyun DHD_FLOW_QUEUE_SET_THRESHOLD(queue, max);
151*4882a593Smuzhiyun DHD_FLOW_QUEUE_SET_CLEN(queue, &dhdp->cumm_ctr);
152*4882a593Smuzhiyun DHD_FLOW_QUEUE_SET_L2CLEN(queue, &dhdp->l2cumm_ctr);
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun queue->failures = 0U;
155*4882a593Smuzhiyun queue->cb = &dhd_flow_queue_overflow;
156*4882a593Smuzhiyun }
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun /** Initialize a flow ring's queue, called on driver initialization. */
159*4882a593Smuzhiyun void
dhd_flow_queue_init(dhd_pub_t * dhdp,flow_queue_t * queue,int max)160*4882a593Smuzhiyun dhd_flow_queue_init(dhd_pub_t *dhdp, flow_queue_t *queue, int max)
161*4882a593Smuzhiyun {
162*4882a593Smuzhiyun ASSERT((queue != NULL) && (max > 0));
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun dll_init(&queue->list);
165*4882a593Smuzhiyun dhd_flow_queue_reinit(dhdp, queue, max);
166*4882a593Smuzhiyun }
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun /** Register an enqueue overflow callback handler */
169*4882a593Smuzhiyun void
dhd_flow_queue_register(flow_queue_t * queue,flow_queue_cb_t cb)170*4882a593Smuzhiyun dhd_flow_queue_register(flow_queue_t *queue, flow_queue_cb_t cb)
171*4882a593Smuzhiyun {
172*4882a593Smuzhiyun ASSERT(queue != NULL);
173*4882a593Smuzhiyun queue->cb = cb;
174*4882a593Smuzhiyun }
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun /**
177*4882a593Smuzhiyun * Enqueue an 802.3 packet at the back of a flow ring's queue. From there, it will travel later on
178*4882a593Smuzhiyun * to the flow ring itself.
179*4882a593Smuzhiyun */
180*4882a593Smuzhiyun int
BCMFASTPATH(dhd_flow_queue_enqueue)181*4882a593Smuzhiyun BCMFASTPATH(dhd_flow_queue_enqueue)(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt)
182*4882a593Smuzhiyun {
183*4882a593Smuzhiyun int ret = BCME_OK;
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun ASSERT(queue != NULL);
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun if (dhd_flow_queue_throttle(queue)) {
188*4882a593Smuzhiyun queue->failures++;
189*4882a593Smuzhiyun ret = (*queue->cb)(queue, pkt);
190*4882a593Smuzhiyun goto done;
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun if (queue->head) {
194*4882a593Smuzhiyun FLOW_QUEUE_PKT_SETNEXT(queue->tail, pkt);
195*4882a593Smuzhiyun } else {
196*4882a593Smuzhiyun queue->head = pkt;
197*4882a593Smuzhiyun }
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun FLOW_QUEUE_PKT_SETNEXT(pkt, NULL);
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun queue->tail = pkt; /* at tail */
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun queue->len++;
204*4882a593Smuzhiyun /* increment parent's cummulative length */
205*4882a593Smuzhiyun DHD_CUMM_CTR_INCR(DHD_FLOW_QUEUE_CLEN_PTR(queue));
206*4882a593Smuzhiyun /* increment grandparent's cummulative length */
207*4882a593Smuzhiyun DHD_CUMM_CTR_INCR(DHD_FLOW_QUEUE_L2CLEN_PTR(queue));
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun done:
210*4882a593Smuzhiyun return ret;
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun
BCMFASTPATH(dhd_flow_queue_enqueue_head)213*4882a593Smuzhiyun int BCMFASTPATH
214*4882a593Smuzhiyun (dhd_flow_queue_enqueue_head)(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt)
215*4882a593Smuzhiyun {
216*4882a593Smuzhiyun int ret = BCME_OK;
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun ASSERT(queue != NULL);
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun if (dhd_flow_queue_throttle(queue)) {
221*4882a593Smuzhiyun queue->failures++;
222*4882a593Smuzhiyun ret = (*queue->cb)(queue, pkt);
223*4882a593Smuzhiyun goto done;
224*4882a593Smuzhiyun }
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun if (queue->head) {
227*4882a593Smuzhiyun FLOW_QUEUE_PKT_SETNEXT(pkt, queue->head);
228*4882a593Smuzhiyun queue->head = pkt;
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun } else {
231*4882a593Smuzhiyun queue->head = pkt;
232*4882a593Smuzhiyun FLOW_QUEUE_PKT_SETNEXT(pkt, NULL);
233*4882a593Smuzhiyun queue->tail = pkt; /* at tail */
234*4882a593Smuzhiyun }
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun queue->len++;
237*4882a593Smuzhiyun /* increment parent's cummulative length */
238*4882a593Smuzhiyun DHD_CUMM_CTR_INCR(DHD_FLOW_QUEUE_CLEN_PTR(queue));
239*4882a593Smuzhiyun /* increment grandparent's cummulative length */
240*4882a593Smuzhiyun DHD_CUMM_CTR_INCR(DHD_FLOW_QUEUE_L2CLEN_PTR(queue));
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun done:
243*4882a593Smuzhiyun return ret;
244*4882a593Smuzhiyun }
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun /** Dequeue an 802.3 packet from a flow ring's queue, from head (FIFO) */
247*4882a593Smuzhiyun void *
BCMFASTPATH(dhd_flow_queue_dequeue)248*4882a593Smuzhiyun BCMFASTPATH(dhd_flow_queue_dequeue)(dhd_pub_t *dhdp, flow_queue_t *queue)
249*4882a593Smuzhiyun {
250*4882a593Smuzhiyun void * pkt;
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun ASSERT(queue != NULL);
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun pkt = queue->head; /* from head */
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun if (pkt == NULL) {
257*4882a593Smuzhiyun ASSERT((queue->len == 0) && (queue->tail == NULL));
258*4882a593Smuzhiyun goto done;
259*4882a593Smuzhiyun }
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun queue->head = FLOW_QUEUE_PKT_NEXT(pkt);
262*4882a593Smuzhiyun if (queue->head == NULL)
263*4882a593Smuzhiyun queue->tail = NULL;
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun queue->len--;
266*4882a593Smuzhiyun /* decrement parent's cummulative length */
267*4882a593Smuzhiyun DHD_CUMM_CTR_DECR(DHD_FLOW_QUEUE_CLEN_PTR(queue));
268*4882a593Smuzhiyun /* decrement grandparent's cummulative length */
269*4882a593Smuzhiyun DHD_CUMM_CTR_DECR(DHD_FLOW_QUEUE_L2CLEN_PTR(queue));
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun FLOW_QUEUE_PKT_SETNEXT(pkt, NULL); /* dettach packet from queue */
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun done:
274*4882a593Smuzhiyun return pkt;
275*4882a593Smuzhiyun }
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun /** Reinsert a dequeued 802.3 packet back at the head */
278*4882a593Smuzhiyun void
BCMFASTPATH(dhd_flow_queue_reinsert)279*4882a593Smuzhiyun BCMFASTPATH(dhd_flow_queue_reinsert)(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt)
280*4882a593Smuzhiyun {
281*4882a593Smuzhiyun if (queue->head == NULL) {
282*4882a593Smuzhiyun queue->tail = pkt;
283*4882a593Smuzhiyun }
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun FLOW_QUEUE_PKT_SETNEXT(pkt, queue->head);
286*4882a593Smuzhiyun queue->head = pkt;
287*4882a593Smuzhiyun queue->len++;
288*4882a593Smuzhiyun /* increment parent's cummulative length */
289*4882a593Smuzhiyun DHD_CUMM_CTR_INCR(DHD_FLOW_QUEUE_CLEN_PTR(queue));
290*4882a593Smuzhiyun /* increment grandparent's cummulative length */
291*4882a593Smuzhiyun DHD_CUMM_CTR_INCR(DHD_FLOW_QUEUE_L2CLEN_PTR(queue));
292*4882a593Smuzhiyun }
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun /** Fetch the backup queue for a flowring, and assign flow control thresholds */
295*4882a593Smuzhiyun void
dhd_flow_ring_config_thresholds(dhd_pub_t * dhdp,uint16 flowid,int queue_budget,int cumm_threshold,void * cumm_ctr,int l2cumm_threshold,void * l2cumm_ctr)296*4882a593Smuzhiyun dhd_flow_ring_config_thresholds(dhd_pub_t *dhdp, uint16 flowid,
297*4882a593Smuzhiyun int queue_budget, int cumm_threshold, void *cumm_ctr,
298*4882a593Smuzhiyun int l2cumm_threshold, void *l2cumm_ctr)
299*4882a593Smuzhiyun {
300*4882a593Smuzhiyun flow_queue_t * queue = NULL;
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun ASSERT(dhdp != (dhd_pub_t*)NULL);
303*4882a593Smuzhiyun ASSERT(queue_budget > 1);
304*4882a593Smuzhiyun ASSERT(cumm_threshold > 1);
305*4882a593Smuzhiyun ASSERT(cumm_ctr != (void*)NULL);
306*4882a593Smuzhiyun ASSERT(l2cumm_threshold > 1);
307*4882a593Smuzhiyun ASSERT(l2cumm_ctr != (void*)NULL);
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun queue = dhd_flow_queue(dhdp, flowid);
310*4882a593Smuzhiyun if (queue) {
311*4882a593Smuzhiyun DHD_FLOW_QUEUE_SET_MAX(queue, queue_budget); /* Max queue length */
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun /* Set the queue's parent threshold and cummulative counter */
314*4882a593Smuzhiyun DHD_FLOW_QUEUE_SET_THRESHOLD(queue, cumm_threshold);
315*4882a593Smuzhiyun DHD_FLOW_QUEUE_SET_CLEN(queue, cumm_ctr);
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun /* Set the queue's grandparent threshold and cummulative counter */
318*4882a593Smuzhiyun DHD_FLOW_QUEUE_SET_L2THRESHOLD(queue, l2cumm_threshold);
319*4882a593Smuzhiyun DHD_FLOW_QUEUE_SET_L2CLEN(queue, l2cumm_ctr);
320*4882a593Smuzhiyun }
321*4882a593Smuzhiyun }
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun /*
324*4882a593Smuzhiyun * This function returns total number of flowrings that can be created for a INFRA STA.
325*4882a593Smuzhiyun * For prio2ac mapping, it will return 4, prio2ac[8] = { 0, 1, 1, 0, 2, 2, 3, 3 }
326*4882a593Smuzhiyun * For prio2tid mapping, it will return 8, prio2tid[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }
327*4882a593Smuzhiyun */
328*4882a593Smuzhiyun uint8
dhd_num_prio_supported_per_flow_ring(dhd_pub_t * dhdp)329*4882a593Smuzhiyun dhd_num_prio_supported_per_flow_ring(dhd_pub_t *dhdp)
330*4882a593Smuzhiyun {
331*4882a593Smuzhiyun uint8 prio_count = 0;
332*4882a593Smuzhiyun int i;
333*4882a593Smuzhiyun /* Pick all elements one by one */
334*4882a593Smuzhiyun for (i = 0; i < NUMPRIO; i++)
335*4882a593Smuzhiyun {
336*4882a593Smuzhiyun /* Check if the picked element is already counted */
337*4882a593Smuzhiyun int j;
338*4882a593Smuzhiyun for (j = 0; j < i; j++) {
339*4882a593Smuzhiyun if (dhdp->flow_prio_map[i] == dhdp->flow_prio_map[j]) {
340*4882a593Smuzhiyun break;
341*4882a593Smuzhiyun }
342*4882a593Smuzhiyun }
343*4882a593Smuzhiyun /* If not counted earlier, then count it */
344*4882a593Smuzhiyun if (i == j) {
345*4882a593Smuzhiyun prio_count++;
346*4882a593Smuzhiyun }
347*4882a593Smuzhiyun }
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun return prio_count;
350*4882a593Smuzhiyun }
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun uint8
dhd_get_max_multi_client_flow_rings(dhd_pub_t * dhdp)353*4882a593Smuzhiyun dhd_get_max_multi_client_flow_rings(dhd_pub_t *dhdp)
354*4882a593Smuzhiyun {
355*4882a593Smuzhiyun uint8 reserved_infra_sta_flow_rings = dhd_num_prio_supported_per_flow_ring(dhdp);
356*4882a593Smuzhiyun uint8 total_tx_flow_rings = (uint8)dhd_get_max_flow_rings(dhdp);
357*4882a593Smuzhiyun uint8 max_multi_client_flow_rings = total_tx_flow_rings - reserved_infra_sta_flow_rings;
358*4882a593Smuzhiyun return max_multi_client_flow_rings;
359*4882a593Smuzhiyun }
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun int
dhd_flowid_map_init(dhd_pub_t * dhdp,uint16 max_tx_flow_rings)362*4882a593Smuzhiyun dhd_flowid_map_init(dhd_pub_t *dhdp, uint16 max_tx_flow_rings)
363*4882a593Smuzhiyun {
364*4882a593Smuzhiyun #if defined(DHD_HTPUT_TUNABLES)
365*4882a593Smuzhiyun uint16 max_normal_tx_flow_rings = max_tx_flow_rings - HTPUT_TOTAL_FLOW_RINGS;
366*4882a593Smuzhiyun #else
367*4882a593Smuzhiyun uint16 max_normal_tx_flow_rings = max_tx_flow_rings;
368*4882a593Smuzhiyun #endif /* DHD_HTPUT_TUNABLES */
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun /* Construct a normal flowid allocator from FLOWID_RESERVED to
371*4882a593Smuzhiyun * (max_normal_tx_flow_rings - 1)
372*4882a593Smuzhiyun */
373*4882a593Smuzhiyun dhdp->flowid_allocator = id16_map_init(dhdp->osh, max_normal_tx_flow_rings,
374*4882a593Smuzhiyun FLOWID_RESERVED);
375*4882a593Smuzhiyun if (dhdp->flowid_allocator == NULL) {
376*4882a593Smuzhiyun DHD_ERROR(("%s: flowid allocator init failure\n", __FUNCTION__));
377*4882a593Smuzhiyun return BCME_NOMEM;
378*4882a593Smuzhiyun }
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun #if defined(DHD_HTPUT_TUNABLES)
381*4882a593Smuzhiyun if (HTPUT_TOTAL_FLOW_RINGS > 0) {
382*4882a593Smuzhiyun dhdp->htput_flow_ring_start = max_normal_tx_flow_rings + FLOWID_RESERVED;
383*4882a593Smuzhiyun /* Construct a htput flowid allocator from htput_flow_ring_start to
384*4882a593Smuzhiyun * (htput_flow_ring_start + HTPUT_TOTAL_FLOW_RINGS - 1)
385*4882a593Smuzhiyun */
386*4882a593Smuzhiyun dhdp->htput_flowid_allocator = id16_map_init(dhdp->osh, HTPUT_TOTAL_FLOW_RINGS,
387*4882a593Smuzhiyun dhdp->htput_flow_ring_start);
388*4882a593Smuzhiyun if (dhdp->htput_flowid_allocator == NULL) {
389*4882a593Smuzhiyun DHD_ERROR(("%s: htput flowid allocator init failure\n", __FUNCTION__));
390*4882a593Smuzhiyun return BCME_NOMEM;
391*4882a593Smuzhiyun }
392*4882a593Smuzhiyun dhdp->htput_client_flow_rings = 0u;
393*4882a593Smuzhiyun }
394*4882a593Smuzhiyun #endif /* !DHD_HTPUT_TUNABLES */
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun return BCME_OK;
397*4882a593Smuzhiyun }
398*4882a593Smuzhiyun
399*4882a593Smuzhiyun void
dhd_flowid_map_deinit(dhd_pub_t * dhdp)400*4882a593Smuzhiyun dhd_flowid_map_deinit(dhd_pub_t *dhdp)
401*4882a593Smuzhiyun {
402*4882a593Smuzhiyun if (dhdp->flowid_allocator) {
403*4882a593Smuzhiyun dhdp->flowid_allocator = id16_map_fini(dhdp->osh, dhdp->flowid_allocator);
404*4882a593Smuzhiyun }
405*4882a593Smuzhiyun ASSERT(dhdp->flowid_allocator == NULL);
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun #if defined(DHD_HTPUT_TUNABLES)
408*4882a593Smuzhiyun if (dhdp->htput_flowid_allocator) {
409*4882a593Smuzhiyun dhdp->htput_flowid_allocator = id16_map_fini(dhdp->osh,
410*4882a593Smuzhiyun dhdp->htput_flowid_allocator);
411*4882a593Smuzhiyun ASSERT(dhdp->htput_flowid_allocator == NULL);
412*4882a593Smuzhiyun }
413*4882a593Smuzhiyun dhdp->htput_client_flow_rings = 0u;
414*4882a593Smuzhiyun #endif /* !DHD_HTPUT_TUNABLES */
415*4882a593Smuzhiyun return;
416*4882a593Smuzhiyun }
417*4882a593Smuzhiyun
418*4882a593Smuzhiyun /** Initializes data structures of multiple flow rings
419*4882a593Smuzhiyun * num_h2d_rings - max_h2d_rings including static and dynamic rings
420*4882a593Smuzhiyun */
421*4882a593Smuzhiyun int
dhd_flow_rings_init(dhd_pub_t * dhdp,uint32 num_h2d_rings)422*4882a593Smuzhiyun dhd_flow_rings_init(dhd_pub_t *dhdp, uint32 num_h2d_rings)
423*4882a593Smuzhiyun {
424*4882a593Smuzhiyun uint32 idx;
425*4882a593Smuzhiyun uint32 flow_ring_table_sz = 0;
426*4882a593Smuzhiyun uint32 if_flow_lkup_sz = 0;
427*4882a593Smuzhiyun flow_ring_table_t *flow_ring_table = NULL;
428*4882a593Smuzhiyun if_flow_lkup_t *if_flow_lkup = NULL;
429*4882a593Smuzhiyun void *lock = NULL;
430*4882a593Smuzhiyun void *list_lock = NULL;
431*4882a593Smuzhiyun unsigned long flags;
432*4882a593Smuzhiyun uint16 max_tx_flow_rings;
433*4882a593Smuzhiyun
434*4882a593Smuzhiyun DHD_INFO(("%s\n", __FUNCTION__));
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun /*
437*4882a593Smuzhiyun * Only 16-bit flowid map will be allocated for actual number of Tx flowrings
438*4882a593Smuzhiyun * excluding common rings.
439*4882a593Smuzhiyun * Rest all flowring data structure will be allocated for all num_h2d_rings.
440*4882a593Smuzhiyun */
441*4882a593Smuzhiyun max_tx_flow_rings = dhd_get_max_flow_rings(dhdp);
442*4882a593Smuzhiyun if (dhd_flowid_map_init(dhdp, max_tx_flow_rings) != BCME_OK) {
443*4882a593Smuzhiyun DHD_ERROR(("%s: dhd_flowid_map_init failure\n", __FUNCTION__));
444*4882a593Smuzhiyun goto fail;
445*4882a593Smuzhiyun }
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun /* Any Tx flow id should not be > max_tx_flowid */
448*4882a593Smuzhiyun dhdp->max_tx_flowid = max_tx_flow_rings + FLOWID_RESERVED - 1;
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun /* Allocate a flow ring table, comprising of requested number of rings */
451*4882a593Smuzhiyun flow_ring_table_sz = (num_h2d_rings * sizeof(flow_ring_node_t));
452*4882a593Smuzhiyun flow_ring_table = (flow_ring_table_t *)MALLOCZ(dhdp->osh, flow_ring_table_sz);
453*4882a593Smuzhiyun if (flow_ring_table == NULL) {
454*4882a593Smuzhiyun DHD_ERROR(("%s: flow ring table alloc failure\n", __FUNCTION__));
455*4882a593Smuzhiyun goto fail;
456*4882a593Smuzhiyun }
457*4882a593Smuzhiyun
458*4882a593Smuzhiyun /* Initialize flow ring table state */
459*4882a593Smuzhiyun DHD_CUMM_CTR_INIT(&dhdp->cumm_ctr);
460*4882a593Smuzhiyun DHD_CUMM_CTR_INIT(&dhdp->l2cumm_ctr);
461*4882a593Smuzhiyun bzero((uchar *)flow_ring_table, flow_ring_table_sz);
462*4882a593Smuzhiyun for (idx = 0; idx < num_h2d_rings; idx++) {
463*4882a593Smuzhiyun flow_ring_table[idx].status = FLOW_RING_STATUS_CLOSED;
464*4882a593Smuzhiyun flow_ring_table[idx].flowid = (uint16)idx;
465*4882a593Smuzhiyun flow_ring_table[idx].lock = osl_spin_lock_init(dhdp->osh);
466*4882a593Smuzhiyun #ifdef IDLE_TX_FLOW_MGMT
467*4882a593Smuzhiyun flow_ring_table[idx].last_active_ts = OSL_SYSUPTIME();
468*4882a593Smuzhiyun #endif /* IDLE_TX_FLOW_MGMT */
469*4882a593Smuzhiyun if (flow_ring_table[idx].lock == NULL) {
470*4882a593Smuzhiyun DHD_ERROR(("%s: Failed to init spinlock for queue!\n", __FUNCTION__));
471*4882a593Smuzhiyun goto fail;
472*4882a593Smuzhiyun }
473*4882a593Smuzhiyun
474*4882a593Smuzhiyun dll_init(&flow_ring_table[idx].list);
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun /* Initialize the per flow ring backup queue */
477*4882a593Smuzhiyun dhd_flow_queue_init(dhdp, &flow_ring_table[idx].queue,
478*4882a593Smuzhiyun dhdp->conf->flow_ring_queue_threshold);
479*4882a593Smuzhiyun }
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun /* Allocate per interface hash table (for fast lookup from interface to flow ring) */
482*4882a593Smuzhiyun if_flow_lkup_sz = sizeof(if_flow_lkup_t) * DHD_MAX_IFS;
483*4882a593Smuzhiyun if_flow_lkup = (if_flow_lkup_t *)DHD_OS_PREALLOC(dhdp,
484*4882a593Smuzhiyun DHD_PREALLOC_IF_FLOW_LKUP, if_flow_lkup_sz);
485*4882a593Smuzhiyun if (if_flow_lkup == NULL) {
486*4882a593Smuzhiyun DHD_ERROR(("%s: if flow lkup alloc failure\n", __FUNCTION__));
487*4882a593Smuzhiyun goto fail;
488*4882a593Smuzhiyun }
489*4882a593Smuzhiyun
490*4882a593Smuzhiyun /* Initialize per interface hash table */
491*4882a593Smuzhiyun for (idx = 0; idx < DHD_MAX_IFS; idx++) {
492*4882a593Smuzhiyun int hash_ix;
493*4882a593Smuzhiyun if_flow_lkup[idx].status = 0;
494*4882a593Smuzhiyun if_flow_lkup[idx].role = 0;
495*4882a593Smuzhiyun for (hash_ix = 0; hash_ix < DHD_FLOWRING_HASH_SIZE; hash_ix++)
496*4882a593Smuzhiyun if_flow_lkup[idx].fl_hash[hash_ix] = NULL;
497*4882a593Smuzhiyun }
498*4882a593Smuzhiyun
499*4882a593Smuzhiyun lock = osl_spin_lock_init(dhdp->osh);
500*4882a593Smuzhiyun if (lock == NULL)
501*4882a593Smuzhiyun goto fail;
502*4882a593Smuzhiyun
503*4882a593Smuzhiyun list_lock = osl_spin_lock_init(dhdp->osh);
504*4882a593Smuzhiyun if (list_lock == NULL)
505*4882a593Smuzhiyun goto lock_fail;
506*4882a593Smuzhiyun
507*4882a593Smuzhiyun dhdp->flow_prio_map_type = DHD_FLOW_PRIO_AC_MAP;
508*4882a593Smuzhiyun bcopy(prio2ac, dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO);
509*4882a593Smuzhiyun
510*4882a593Smuzhiyun dhdp->max_multi_client_flow_rings = dhd_get_max_multi_client_flow_rings(dhdp);
511*4882a593Smuzhiyun dhdp->multi_client_flow_rings = 0U;
512*4882a593Smuzhiyun
513*4882a593Smuzhiyun #ifdef DHD_LOSSLESS_ROAMING
514*4882a593Smuzhiyun dhdp->dequeue_prec_map = ALLPRIO;
515*4882a593Smuzhiyun #endif
516*4882a593Smuzhiyun /* Now populate into dhd pub */
517*4882a593Smuzhiyun DHD_FLOWID_LOCK(lock, flags);
518*4882a593Smuzhiyun dhdp->num_h2d_rings = num_h2d_rings;
519*4882a593Smuzhiyun dhdp->flow_ring_table = (void *)flow_ring_table;
520*4882a593Smuzhiyun dhdp->if_flow_lkup = (void *)if_flow_lkup;
521*4882a593Smuzhiyun dhdp->flowid_lock = lock;
522*4882a593Smuzhiyun dhdp->flow_rings_inited = TRUE;
523*4882a593Smuzhiyun dhdp->flowring_list_lock = list_lock;
524*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(lock, flags);
525*4882a593Smuzhiyun
526*4882a593Smuzhiyun DHD_INFO(("%s done\n", __FUNCTION__));
527*4882a593Smuzhiyun return BCME_OK;
528*4882a593Smuzhiyun
529*4882a593Smuzhiyun lock_fail:
530*4882a593Smuzhiyun /* deinit the spinlock */
531*4882a593Smuzhiyun osl_spin_lock_deinit(dhdp->osh, lock);
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun fail:
534*4882a593Smuzhiyun /* Destruct the per interface flow lkup table */
535*4882a593Smuzhiyun if (if_flow_lkup != NULL) {
536*4882a593Smuzhiyun DHD_OS_PREFREE(dhdp, if_flow_lkup, if_flow_lkup_sz);
537*4882a593Smuzhiyun }
538*4882a593Smuzhiyun if (flow_ring_table != NULL) {
539*4882a593Smuzhiyun for (idx = 0; idx < num_h2d_rings; idx++) {
540*4882a593Smuzhiyun if (flow_ring_table[idx].lock != NULL)
541*4882a593Smuzhiyun osl_spin_lock_deinit(dhdp->osh, flow_ring_table[idx].lock);
542*4882a593Smuzhiyun }
543*4882a593Smuzhiyun MFREE(dhdp->osh, flow_ring_table, flow_ring_table_sz);
544*4882a593Smuzhiyun }
545*4882a593Smuzhiyun dhd_flowid_map_deinit(dhdp);
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun return BCME_NOMEM;
548*4882a593Smuzhiyun }
549*4882a593Smuzhiyun
550*4882a593Smuzhiyun /** Deinit Flow Ring specific data structures */
dhd_flow_rings_deinit(dhd_pub_t * dhdp)551*4882a593Smuzhiyun void dhd_flow_rings_deinit(dhd_pub_t *dhdp)
552*4882a593Smuzhiyun {
553*4882a593Smuzhiyun uint16 idx;
554*4882a593Smuzhiyun uint32 flow_ring_table_sz;
555*4882a593Smuzhiyun uint32 if_flow_lkup_sz;
556*4882a593Smuzhiyun flow_ring_table_t *flow_ring_table;
557*4882a593Smuzhiyun unsigned long flags;
558*4882a593Smuzhiyun void *lock;
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun DHD_INFO(("dhd_flow_rings_deinit\n"));
561*4882a593Smuzhiyun
562*4882a593Smuzhiyun if (!(dhdp->flow_rings_inited)) {
563*4882a593Smuzhiyun DHD_ERROR(("dhd_flow_rings not initialized!\n"));
564*4882a593Smuzhiyun return;
565*4882a593Smuzhiyun }
566*4882a593Smuzhiyun
567*4882a593Smuzhiyun if (dhdp->flow_ring_table != NULL) {
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun ASSERT(dhdp->num_h2d_rings > 0);
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
572*4882a593Smuzhiyun flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table;
573*4882a593Smuzhiyun dhdp->flow_ring_table = NULL;
574*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
575*4882a593Smuzhiyun for (idx = 0; idx < dhdp->num_h2d_rings; idx++) {
576*4882a593Smuzhiyun if (flow_ring_table[idx].active) {
577*4882a593Smuzhiyun dhd_bus_clean_flow_ring(dhdp->bus, &flow_ring_table[idx]);
578*4882a593Smuzhiyun }
579*4882a593Smuzhiyun ASSERT(DHD_FLOW_QUEUE_EMPTY(&flow_ring_table[idx].queue));
580*4882a593Smuzhiyun
581*4882a593Smuzhiyun /* Deinit flow ring queue locks before destroying flow ring table */
582*4882a593Smuzhiyun if (flow_ring_table[idx].lock != NULL) {
583*4882a593Smuzhiyun osl_spin_lock_deinit(dhdp->osh, flow_ring_table[idx].lock);
584*4882a593Smuzhiyun }
585*4882a593Smuzhiyun flow_ring_table[idx].lock = NULL;
586*4882a593Smuzhiyun
587*4882a593Smuzhiyun }
588*4882a593Smuzhiyun
589*4882a593Smuzhiyun /* Destruct the flow ring table */
590*4882a593Smuzhiyun flow_ring_table_sz = dhdp->num_h2d_rings * sizeof(flow_ring_table_t);
591*4882a593Smuzhiyun MFREE(dhdp->osh, flow_ring_table, flow_ring_table_sz);
592*4882a593Smuzhiyun }
593*4882a593Smuzhiyun
594*4882a593Smuzhiyun DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
595*4882a593Smuzhiyun
596*4882a593Smuzhiyun /* Destruct the per interface flow lkup table */
597*4882a593Smuzhiyun if (dhdp->if_flow_lkup != NULL) {
598*4882a593Smuzhiyun if_flow_lkup_sz = sizeof(if_flow_lkup_t) * DHD_MAX_IFS;
599*4882a593Smuzhiyun bzero((uchar *)dhdp->if_flow_lkup, if_flow_lkup_sz);
600*4882a593Smuzhiyun DHD_OS_PREFREE(dhdp, dhdp->if_flow_lkup, if_flow_lkup_sz);
601*4882a593Smuzhiyun dhdp->if_flow_lkup = NULL;
602*4882a593Smuzhiyun }
603*4882a593Smuzhiyun
604*4882a593Smuzhiyun /* Destruct the flowid allocator */
605*4882a593Smuzhiyun dhd_flowid_map_deinit(dhdp);
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun dhdp->num_h2d_rings = 0U;
608*4882a593Smuzhiyun bzero(dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO);
609*4882a593Smuzhiyun
610*4882a593Smuzhiyun dhdp->max_multi_client_flow_rings = 0U;
611*4882a593Smuzhiyun dhdp->multi_client_flow_rings = 0U;
612*4882a593Smuzhiyun
613*4882a593Smuzhiyun lock = dhdp->flowid_lock;
614*4882a593Smuzhiyun dhdp->flowid_lock = NULL;
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun if (lock) {
617*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(lock, flags);
618*4882a593Smuzhiyun osl_spin_lock_deinit(dhdp->osh, lock);
619*4882a593Smuzhiyun }
620*4882a593Smuzhiyun
621*4882a593Smuzhiyun osl_spin_lock_deinit(dhdp->osh, dhdp->flowring_list_lock);
622*4882a593Smuzhiyun dhdp->flowring_list_lock = NULL;
623*4882a593Smuzhiyun
624*4882a593Smuzhiyun ASSERT(dhdp->if_flow_lkup == NULL);
625*4882a593Smuzhiyun ASSERT(dhdp->flow_ring_table == NULL);
626*4882a593Smuzhiyun dhdp->flow_rings_inited = FALSE;
627*4882a593Smuzhiyun }
628*4882a593Smuzhiyun
629*4882a593Smuzhiyun /** Uses hash table to quickly map from ifindex to a flow ring 'role' (STA/AP) */
630*4882a593Smuzhiyun uint8
dhd_flow_rings_ifindex2role(dhd_pub_t * dhdp,uint8 ifindex)631*4882a593Smuzhiyun dhd_flow_rings_ifindex2role(dhd_pub_t *dhdp, uint8 ifindex)
632*4882a593Smuzhiyun {
633*4882a593Smuzhiyun if_flow_lkup_t *if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
634*4882a593Smuzhiyun ASSERT(if_flow_lkup);
635*4882a593Smuzhiyun return if_flow_lkup[ifindex].role;
636*4882a593Smuzhiyun }
637*4882a593Smuzhiyun
638*4882a593Smuzhiyun #ifdef WLTDLS
is_tdls_destination(dhd_pub_t * dhdp,uint8 * da)639*4882a593Smuzhiyun bool is_tdls_destination(dhd_pub_t *dhdp, uint8 *da)
640*4882a593Smuzhiyun {
641*4882a593Smuzhiyun unsigned long flags;
642*4882a593Smuzhiyun tdls_peer_node_t *cur = NULL;
643*4882a593Smuzhiyun
644*4882a593Smuzhiyun DHD_TDLS_LOCK(&dhdp->tdls_lock, flags);
645*4882a593Smuzhiyun /* Check only if tdls peer is added */
646*4882a593Smuzhiyun if (dhdp->peer_tbl.tdls_peer_count && !(ETHER_ISMULTI(da))) {
647*4882a593Smuzhiyun cur = dhdp->peer_tbl.node;
648*4882a593Smuzhiyun
649*4882a593Smuzhiyun while (cur != NULL) {
650*4882a593Smuzhiyun if (!memcmp(da, cur->addr, ETHER_ADDR_LEN)) {
651*4882a593Smuzhiyun DHD_TDLS_UNLOCK(&dhdp->tdls_lock, flags);
652*4882a593Smuzhiyun return TRUE;
653*4882a593Smuzhiyun }
654*4882a593Smuzhiyun cur = cur->next;
655*4882a593Smuzhiyun }
656*4882a593Smuzhiyun }
657*4882a593Smuzhiyun DHD_TDLS_UNLOCK(&dhdp->tdls_lock, flags);
658*4882a593Smuzhiyun return FALSE;
659*4882a593Smuzhiyun }
660*4882a593Smuzhiyun #endif /* WLTDLS */
661*4882a593Smuzhiyun
662*4882a593Smuzhiyun /** Uses hash table to quickly map from ifindex+prio+da to a flow ring id */
663*4882a593Smuzhiyun static INLINE uint16
dhd_flowid_find(dhd_pub_t * dhdp,uint8 ifindex,uint8 prio,char * sa,char * da)664*4882a593Smuzhiyun dhd_flowid_find(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, char *sa, char *da)
665*4882a593Smuzhiyun {
666*4882a593Smuzhiyun int hash;
667*4882a593Smuzhiyun bool ismcast = FALSE;
668*4882a593Smuzhiyun flow_hash_info_t *cur;
669*4882a593Smuzhiyun if_flow_lkup_t *if_flow_lkup;
670*4882a593Smuzhiyun unsigned long flags;
671*4882a593Smuzhiyun
672*4882a593Smuzhiyun ASSERT(ifindex < DHD_MAX_IFS);
673*4882a593Smuzhiyun if (ifindex >= DHD_MAX_IFS)
674*4882a593Smuzhiyun return FLOWID_INVALID;
675*4882a593Smuzhiyun
676*4882a593Smuzhiyun DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
677*4882a593Smuzhiyun if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
678*4882a593Smuzhiyun
679*4882a593Smuzhiyun ASSERT(if_flow_lkup);
680*4882a593Smuzhiyun
681*4882a593Smuzhiyun if (DHD_IF_ROLE_GENERIC_STA(dhdp, ifindex)) {
682*4882a593Smuzhiyun #ifdef WLTDLS
683*4882a593Smuzhiyun if (is_tdls_destination(dhdp, da)) {
684*4882a593Smuzhiyun hash = DHD_FLOWRING_HASHINDEX(da, prio);
685*4882a593Smuzhiyun cur = if_flow_lkup[ifindex].fl_hash[hash];
686*4882a593Smuzhiyun while (cur != NULL) {
687*4882a593Smuzhiyun if (!memcmp(cur->flow_info.da, da, ETHER_ADDR_LEN)) {
688*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
689*4882a593Smuzhiyun return cur->flowid;
690*4882a593Smuzhiyun }
691*4882a593Smuzhiyun cur = cur->next;
692*4882a593Smuzhiyun }
693*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
694*4882a593Smuzhiyun return FLOWID_INVALID;
695*4882a593Smuzhiyun }
696*4882a593Smuzhiyun #endif /* WLTDLS */
697*4882a593Smuzhiyun /* For STA non TDLS dest and WDS dest flow ring id is mapped based on prio only */
698*4882a593Smuzhiyun cur = if_flow_lkup[ifindex].fl_hash[prio];
699*4882a593Smuzhiyun if (cur) {
700*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
701*4882a593Smuzhiyun return cur->flowid;
702*4882a593Smuzhiyun }
703*4882a593Smuzhiyun } else {
704*4882a593Smuzhiyun
705*4882a593Smuzhiyun if (ETHER_ISMULTI(da)) {
706*4882a593Smuzhiyun ismcast = TRUE;
707*4882a593Smuzhiyun hash = 0;
708*4882a593Smuzhiyun } else {
709*4882a593Smuzhiyun hash = DHD_FLOWRING_HASHINDEX(da, prio);
710*4882a593Smuzhiyun }
711*4882a593Smuzhiyun
712*4882a593Smuzhiyun cur = if_flow_lkup[ifindex].fl_hash[hash];
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun while (cur) {
715*4882a593Smuzhiyun if ((ismcast && ETHER_ISMULTI(cur->flow_info.da)) ||
716*4882a593Smuzhiyun (!memcmp(cur->flow_info.da, da, ETHER_ADDR_LEN) &&
717*4882a593Smuzhiyun (cur->flow_info.tid == prio))) {
718*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
719*4882a593Smuzhiyun return cur->flowid;
720*4882a593Smuzhiyun }
721*4882a593Smuzhiyun cur = cur->next;
722*4882a593Smuzhiyun }
723*4882a593Smuzhiyun }
724*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
725*4882a593Smuzhiyun
726*4882a593Smuzhiyun #ifdef DHD_EFI
727*4882a593Smuzhiyun DHD_TRACE(("%s: cannot find flowid\n", __FUNCTION__));
728*4882a593Smuzhiyun #else
729*4882a593Smuzhiyun DHD_FLOWRING_INFO(("%s: cannot find flowid\n", __FUNCTION__));
730*4882a593Smuzhiyun #endif
731*4882a593Smuzhiyun return FLOWID_INVALID;
732*4882a593Smuzhiyun } /* dhd_flowid_find */
733*4882a593Smuzhiyun
734*4882a593Smuzhiyun static uint16
dhd_flowid_map_alloc(dhd_pub_t * dhdp,uint8 ifindex,uint8 prio,char * da)735*4882a593Smuzhiyun dhd_flowid_map_alloc(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, char *da)
736*4882a593Smuzhiyun {
737*4882a593Smuzhiyun uint16 flowid = FLOWID_INVALID;
738*4882a593Smuzhiyun ASSERT(dhdp->flowid_allocator != NULL);
739*4882a593Smuzhiyun
740*4882a593Smuzhiyun #if defined(DHD_HTPUT_TUNABLES)
741*4882a593Smuzhiyun if (dhdp->htput_flowid_allocator) {
742*4882a593Smuzhiyun if (prio == HTPUT_FLOW_RING_PRIO) {
743*4882a593Smuzhiyun if (DHD_IF_ROLE_GENERIC_STA(dhdp, ifindex)) {
744*4882a593Smuzhiyun /* For STA case, only one flowring per PRIO is created,
745*4882a593Smuzhiyun * so no need to have a HTPUT counter variable for STA case.
746*4882a593Smuzhiyun * If already HTPUT flowring is allocated for given HTPUT_PRIO,
747*4882a593Smuzhiyun * then this function will not even get called as dhd_flowid_find
748*4882a593Smuzhiyun * will take care assigning same for those HTPUT_PRIO packets.
749*4882a593Smuzhiyun */
750*4882a593Smuzhiyun flowid = id16_map_alloc(dhdp->htput_flowid_allocator);
751*4882a593Smuzhiyun } else if (DHD_IF_ROLE_MULTI_CLIENT(dhdp, ifindex) && !ETHER_ISMULTI(da)) {
752*4882a593Smuzhiyun /* Use HTPUT flowrings for only HTPUT_NUM_CLIENT_FLOW_RINGS */
753*4882a593Smuzhiyun if (dhdp->htput_client_flow_rings < HTPUT_NUM_CLIENT_FLOW_RINGS) {
754*4882a593Smuzhiyun flowid = id16_map_alloc(dhdp->htput_flowid_allocator);
755*4882a593Smuzhiyun /* increment htput client counter */
756*4882a593Smuzhiyun if (flowid != FLOWID_INVALID) {
757*4882a593Smuzhiyun dhdp->htput_client_flow_rings++;
758*4882a593Smuzhiyun }
759*4882a593Smuzhiyun }
760*4882a593Smuzhiyun }
761*4882a593Smuzhiyun }
762*4882a593Smuzhiyun }
763*4882a593Smuzhiyun #endif /* !DHD_HTPUT_TUNABLES */
764*4882a593Smuzhiyun
765*4882a593Smuzhiyun BCM_REFERENCE(flowid);
766*4882a593Smuzhiyun
767*4882a593Smuzhiyun /*
768*4882a593Smuzhiyun * For HTPUT case, if the high throughput flowrings are already allocated
769*4882a593Smuzhiyun * for the given role, the control comes here.
770*4882a593Smuzhiyun */
771*4882a593Smuzhiyun if (flowid == FLOWID_INVALID) {
772*4882a593Smuzhiyun flowid = id16_map_alloc(dhdp->flowid_allocator);
773*4882a593Smuzhiyun }
774*4882a593Smuzhiyun
775*4882a593Smuzhiyun return flowid;
776*4882a593Smuzhiyun }
777*4882a593Smuzhiyun
778*4882a593Smuzhiyun /** Create unique Flow ID, called when a flow ring is created. */
779*4882a593Smuzhiyun static INLINE uint16
dhd_flowid_alloc(dhd_pub_t * dhdp,uint8 ifindex,uint8 prio,char * sa,char * da)780*4882a593Smuzhiyun dhd_flowid_alloc(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, char *sa, char *da)
781*4882a593Smuzhiyun {
782*4882a593Smuzhiyun flow_hash_info_t *fl_hash_node, *cur;
783*4882a593Smuzhiyun if_flow_lkup_t *if_flow_lkup;
784*4882a593Smuzhiyun int hash;
785*4882a593Smuzhiyun uint16 flowid;
786*4882a593Smuzhiyun unsigned long flags;
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun fl_hash_node = (flow_hash_info_t *) MALLOCZ(dhdp->osh, sizeof(flow_hash_info_t));
789*4882a593Smuzhiyun if (fl_hash_node == NULL) {
790*4882a593Smuzhiyun DHD_ERROR(("%s: flow_hash_info_t memory allocation failed \n", __FUNCTION__));
791*4882a593Smuzhiyun return FLOWID_INVALID;
792*4882a593Smuzhiyun }
793*4882a593Smuzhiyun memcpy(fl_hash_node->flow_info.da, da, sizeof(fl_hash_node->flow_info.da));
794*4882a593Smuzhiyun
795*4882a593Smuzhiyun DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
796*4882a593Smuzhiyun flowid = dhd_flowid_map_alloc(dhdp, ifindex, prio, da);
797*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
798*4882a593Smuzhiyun
799*4882a593Smuzhiyun if (flowid == FLOWID_INVALID) {
800*4882a593Smuzhiyun MFREE(dhdp->osh, fl_hash_node, sizeof(flow_hash_info_t));
801*4882a593Smuzhiyun DHD_ERROR_RLMT(("%s: cannot get free flowid \n", __FUNCTION__));
802*4882a593Smuzhiyun return FLOWID_INVALID;
803*4882a593Smuzhiyun }
804*4882a593Smuzhiyun
805*4882a593Smuzhiyun fl_hash_node->flowid = flowid;
806*4882a593Smuzhiyun fl_hash_node->flow_info.tid = prio;
807*4882a593Smuzhiyun fl_hash_node->flow_info.ifindex = ifindex;
808*4882a593Smuzhiyun fl_hash_node->next = NULL;
809*4882a593Smuzhiyun
810*4882a593Smuzhiyun DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
811*4882a593Smuzhiyun if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
812*4882a593Smuzhiyun
813*4882a593Smuzhiyun if (DHD_IF_ROLE_GENERIC_STA(dhdp, ifindex)) {
814*4882a593Smuzhiyun /* For STA/GC non TDLS dest and WDS dest we allocate entry based on prio only */
815*4882a593Smuzhiyun #ifdef WLTDLS
816*4882a593Smuzhiyun if (is_tdls_destination(dhdp, da)) {
817*4882a593Smuzhiyun hash = DHD_FLOWRING_HASHINDEX(da, prio);
818*4882a593Smuzhiyun cur = if_flow_lkup[ifindex].fl_hash[hash];
819*4882a593Smuzhiyun if (cur) {
820*4882a593Smuzhiyun while (cur->next) {
821*4882a593Smuzhiyun cur = cur->next;
822*4882a593Smuzhiyun }
823*4882a593Smuzhiyun cur->next = fl_hash_node;
824*4882a593Smuzhiyun } else {
825*4882a593Smuzhiyun if_flow_lkup[ifindex].fl_hash[hash] = fl_hash_node;
826*4882a593Smuzhiyun }
827*4882a593Smuzhiyun } else
828*4882a593Smuzhiyun #endif /* WLTDLS */
829*4882a593Smuzhiyun if_flow_lkup[ifindex].fl_hash[prio] = fl_hash_node;
830*4882a593Smuzhiyun } else {
831*4882a593Smuzhiyun
832*4882a593Smuzhiyun /* For bcast/mcast assign first slot in in interface */
833*4882a593Smuzhiyun hash = ETHER_ISMULTI(da) ? 0 : DHD_FLOWRING_HASHINDEX(da, prio);
834*4882a593Smuzhiyun cur = if_flow_lkup[ifindex].fl_hash[hash];
835*4882a593Smuzhiyun if (cur) {
836*4882a593Smuzhiyun while (cur->next) {
837*4882a593Smuzhiyun cur = cur->next;
838*4882a593Smuzhiyun }
839*4882a593Smuzhiyun cur->next = fl_hash_node;
840*4882a593Smuzhiyun } else
841*4882a593Smuzhiyun if_flow_lkup[ifindex].fl_hash[hash] = fl_hash_node;
842*4882a593Smuzhiyun }
843*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
844*4882a593Smuzhiyun
845*4882a593Smuzhiyun DHD_FLOWRING_INFO(("%s: allocated flowid %d\n", __FUNCTION__, fl_hash_node->flowid));
846*4882a593Smuzhiyun
847*4882a593Smuzhiyun if (fl_hash_node->flowid > dhdp->max_tx_flowid) {
848*4882a593Smuzhiyun DHD_ERROR(("%s: flowid=%d max_tx_flowid=%d ifindex=%d prio=%d role=%d\n",
849*4882a593Smuzhiyun __FUNCTION__, fl_hash_node->flowid, dhdp->max_tx_flowid,
850*4882a593Smuzhiyun ifindex, prio, if_flow_lkup[ifindex].role));
851*4882a593Smuzhiyun dhd_prhex("da", (uchar *)da, ETHER_ADDR_LEN, DHD_ERROR_VAL);
852*4882a593Smuzhiyun dhd_prhex("sa", (uchar *)sa, ETHER_ADDR_LEN, DHD_ERROR_VAL);
853*4882a593Smuzhiyun return FLOWID_INVALID;
854*4882a593Smuzhiyun }
855*4882a593Smuzhiyun
856*4882a593Smuzhiyun return fl_hash_node->flowid;
857*4882a593Smuzhiyun } /* dhd_flowid_alloc */
858*4882a593Smuzhiyun
859*4882a593Smuzhiyun /** Get flow ring ID, if not present try to create one */
860*4882a593Smuzhiyun static INLINE int
dhd_flowid_lookup(dhd_pub_t * dhdp,uint8 ifindex,uint8 prio,char * sa,char * da,uint16 * flowid)861*4882a593Smuzhiyun dhd_flowid_lookup(dhd_pub_t *dhdp, uint8 ifindex,
862*4882a593Smuzhiyun uint8 prio, char *sa, char *da, uint16 *flowid)
863*4882a593Smuzhiyun {
864*4882a593Smuzhiyun uint16 id;
865*4882a593Smuzhiyun flow_ring_node_t *flow_ring_node;
866*4882a593Smuzhiyun flow_ring_table_t *flow_ring_table;
867*4882a593Smuzhiyun unsigned long flags;
868*4882a593Smuzhiyun int ret;
869*4882a593Smuzhiyun
870*4882a593Smuzhiyun DHD_TRACE(("%s\n", __FUNCTION__));
871*4882a593Smuzhiyun
872*4882a593Smuzhiyun if (!dhdp->flow_ring_table) {
873*4882a593Smuzhiyun return BCME_ERROR;
874*4882a593Smuzhiyun }
875*4882a593Smuzhiyun
876*4882a593Smuzhiyun ASSERT(ifindex < DHD_MAX_IFS);
877*4882a593Smuzhiyun if (ifindex >= DHD_MAX_IFS)
878*4882a593Smuzhiyun return BCME_BADARG;
879*4882a593Smuzhiyun
880*4882a593Smuzhiyun flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table;
881*4882a593Smuzhiyun
882*4882a593Smuzhiyun id = dhd_flowid_find(dhdp, ifindex, prio, sa, da);
883*4882a593Smuzhiyun
884*4882a593Smuzhiyun if (id == FLOWID_INVALID) {
885*4882a593Smuzhiyun bool if_role_multi_client;
886*4882a593Smuzhiyun if_flow_lkup_t *if_flow_lkup;
887*4882a593Smuzhiyun if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
888*4882a593Smuzhiyun
889*4882a593Smuzhiyun if (!if_flow_lkup[ifindex].status)
890*4882a593Smuzhiyun return BCME_ERROR;
891*4882a593Smuzhiyun
892*4882a593Smuzhiyun /* check role for multi client case */
893*4882a593Smuzhiyun if_role_multi_client = DHD_IF_ROLE_MULTI_CLIENT(dhdp, ifindex);
894*4882a593Smuzhiyun
895*4882a593Smuzhiyun /* Abort Flowring creation if multi client flowrings crossed the threshold */
896*4882a593Smuzhiyun #ifdef DHD_LIMIT_MULTI_CLIENT_FLOWRINGS
897*4882a593Smuzhiyun if (if_role_multi_client &&
898*4882a593Smuzhiyun (dhdp->multi_client_flow_rings >= dhdp->max_multi_client_flow_rings)) {
899*4882a593Smuzhiyun DHD_ERROR_RLMT(("%s: Max multi client flow rings reached: %d:%d\n",
900*4882a593Smuzhiyun __FUNCTION__, dhdp->multi_client_flow_rings,
901*4882a593Smuzhiyun dhdp->max_multi_client_flow_rings));
902*4882a593Smuzhiyun return BCME_ERROR;
903*4882a593Smuzhiyun }
904*4882a593Smuzhiyun #endif /* DHD_LIMIT_MULTI_CLIENT_FLOWRINGS */
905*4882a593Smuzhiyun
906*4882a593Smuzhiyun /* Do not create Flowring if peer is not associated */
907*4882a593Smuzhiyun #if (defined(linux) || defined(LINUX)) && defined(PCIE_FULL_DONGLE)
908*4882a593Smuzhiyun if (if_role_multi_client && !ETHER_ISMULTI(da) &&
909*4882a593Smuzhiyun !dhd_sta_associated(dhdp, ifindex, (uint8 *)da)) {
910*4882a593Smuzhiyun DHD_ERROR_RLMT(("%s: Skip send pkt without peer addition\n", __FUNCTION__));
911*4882a593Smuzhiyun return BCME_ERROR;
912*4882a593Smuzhiyun }
913*4882a593Smuzhiyun #endif /* (linux || LINUX) && PCIE_FULL_DONGLE */
914*4882a593Smuzhiyun
915*4882a593Smuzhiyun id = dhd_flowid_alloc(dhdp, ifindex, prio, sa, da);
916*4882a593Smuzhiyun if (id == FLOWID_INVALID) {
917*4882a593Smuzhiyun DHD_ERROR_RLMT(("%s: alloc flowid ifindex %u status %u\n",
918*4882a593Smuzhiyun __FUNCTION__, ifindex, if_flow_lkup[ifindex].status));
919*4882a593Smuzhiyun return BCME_ERROR;
920*4882a593Smuzhiyun }
921*4882a593Smuzhiyun
922*4882a593Smuzhiyun ASSERT(id <= dhdp->max_tx_flowid);
923*4882a593Smuzhiyun
924*4882a593Smuzhiyun /* Only after flowid alloc, increment multi_client_flow_rings */
925*4882a593Smuzhiyun if (if_role_multi_client) {
926*4882a593Smuzhiyun dhdp->multi_client_flow_rings++;
927*4882a593Smuzhiyun }
928*4882a593Smuzhiyun
929*4882a593Smuzhiyun /* register this flowid in dhd_pub */
930*4882a593Smuzhiyun dhd_add_flowid(dhdp, ifindex, prio, da, id);
931*4882a593Smuzhiyun
932*4882a593Smuzhiyun flow_ring_node = (flow_ring_node_t *) &flow_ring_table[id];
933*4882a593Smuzhiyun
934*4882a593Smuzhiyun DHD_FLOWRING_LOCK(flow_ring_node->lock, flags);
935*4882a593Smuzhiyun
936*4882a593Smuzhiyun /* Init Flow info */
937*4882a593Smuzhiyun memcpy(flow_ring_node->flow_info.sa, sa, sizeof(flow_ring_node->flow_info.sa));
938*4882a593Smuzhiyun memcpy(flow_ring_node->flow_info.da, da, sizeof(flow_ring_node->flow_info.da));
939*4882a593Smuzhiyun flow_ring_node->flow_info.tid = prio;
940*4882a593Smuzhiyun flow_ring_node->flow_info.ifindex = ifindex;
941*4882a593Smuzhiyun flow_ring_node->active = TRUE;
942*4882a593Smuzhiyun flow_ring_node->status = FLOW_RING_STATUS_CREATE_PENDING;
943*4882a593Smuzhiyun
944*4882a593Smuzhiyun #ifdef DEVICE_TX_STUCK_DETECT
945*4882a593Smuzhiyun flow_ring_node->tx_cmpl = flow_ring_node->tx_cmpl_prev = OSL_SYSUPTIME();
946*4882a593Smuzhiyun flow_ring_node->stuck_count = 0;
947*4882a593Smuzhiyun #endif /* DEVICE_TX_STUCK_DETECT */
948*4882a593Smuzhiyun #ifdef TX_STATUS_LATENCY_STATS
949*4882a593Smuzhiyun flow_ring_node->flow_info.num_tx_status = 0;
950*4882a593Smuzhiyun flow_ring_node->flow_info.cum_tx_status_latency = 0;
951*4882a593Smuzhiyun flow_ring_node->flow_info.num_tx_pkts = 0;
952*4882a593Smuzhiyun #endif /* TX_STATUS_LATENCY_STATS */
953*4882a593Smuzhiyun #ifdef BCMDBG
954*4882a593Smuzhiyun bzero(&flow_ring_node->flow_info.tx_status[0],
955*4882a593Smuzhiyun sizeof(uint32) * DHD_MAX_TX_STATUS_MSGS);
956*4882a593Smuzhiyun #endif
957*4882a593Smuzhiyun DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags);
958*4882a593Smuzhiyun
959*4882a593Smuzhiyun /* Create and inform device about the new flow */
960*4882a593Smuzhiyun if (dhd_bus_flow_ring_create_request(dhdp->bus, (void *)flow_ring_node)
961*4882a593Smuzhiyun != BCME_OK) {
962*4882a593Smuzhiyun DHD_FLOWRING_LOCK(flow_ring_node->lock, flags);
963*4882a593Smuzhiyun flow_ring_node->status = FLOW_RING_STATUS_CLOSED;
964*4882a593Smuzhiyun flow_ring_node->active = FALSE;
965*4882a593Smuzhiyun DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags);
966*4882a593Smuzhiyun DHD_ERROR(("%s: create error %d\n", __FUNCTION__, id));
967*4882a593Smuzhiyun return BCME_ERROR;
968*4882a593Smuzhiyun }
969*4882a593Smuzhiyun
970*4882a593Smuzhiyun *flowid = id;
971*4882a593Smuzhiyun return BCME_OK;
972*4882a593Smuzhiyun } else {
973*4882a593Smuzhiyun /* if the Flow id was found in the hash */
974*4882a593Smuzhiyun
975*4882a593Smuzhiyun if (id > dhdp->max_tx_flowid) {
976*4882a593Smuzhiyun DHD_ERROR(("%s: Invalid flow id : %u, max_tx_flowid : %u\n",
977*4882a593Smuzhiyun __FUNCTION__, id, dhdp->max_tx_flowid));
978*4882a593Smuzhiyun *flowid = FLOWID_INVALID;
979*4882a593Smuzhiyun ASSERT(0);
980*4882a593Smuzhiyun return BCME_ERROR;
981*4882a593Smuzhiyun }
982*4882a593Smuzhiyun
983*4882a593Smuzhiyun flow_ring_node = (flow_ring_node_t *) &flow_ring_table[id];
984*4882a593Smuzhiyun DHD_FLOWRING_LOCK(flow_ring_node->lock, flags);
985*4882a593Smuzhiyun
986*4882a593Smuzhiyun /*
987*4882a593Smuzhiyun * If the flow_ring_node is in Open State or Status pending state then
988*4882a593Smuzhiyun * we can return the Flow id to the caller.If the flow_ring_node is in
989*4882a593Smuzhiyun * FLOW_RING_STATUS_PENDING this means the creation is in progress and
990*4882a593Smuzhiyun * hence the packets should be queued.
991*4882a593Smuzhiyun *
992*4882a593Smuzhiyun * If the flow_ring_node is in FLOW_RING_STATUS_DELETE_PENDING Or
993*4882a593Smuzhiyun * FLOW_RING_STATUS_CLOSED, then we should return Error.
994*4882a593Smuzhiyun * Note that if the flowing is being deleted we would mark it as
995*4882a593Smuzhiyun * FLOW_RING_STATUS_DELETE_PENDING. Now before Dongle could respond and
996*4882a593Smuzhiyun * before we mark it as FLOW_RING_STATUS_CLOSED we could get tx packets.
997*4882a593Smuzhiyun * We should drop the packets in that case.
998*4882a593Smuzhiyun * The decission to return OK should NOT be based on 'active' variable, beause
999*4882a593Smuzhiyun * active is made TRUE when a flow_ring_node gets allocated and is made
1000*4882a593Smuzhiyun * FALSE when the flow ring gets removed and does not reflect the True state
1001*4882a593Smuzhiyun * of the Flow ring.
1002*4882a593Smuzhiyun * In case if IDLE_TX_FLOW_MGMT is defined, we have to handle two more flowring
1003*4882a593Smuzhiyun * states. If the flow_ring_node's status is FLOW_RING_STATUS_SUSPENDED, the flowid
1004*4882a593Smuzhiyun * is to be returned and from dhd_bus_txdata, the flowring would be resumed again.
1005*4882a593Smuzhiyun * The status FLOW_RING_STATUS_RESUME_PENDING, is equivalent to
1006*4882a593Smuzhiyun * FLOW_RING_STATUS_CREATE_PENDING.
1007*4882a593Smuzhiyun */
1008*4882a593Smuzhiyun if (flow_ring_node->status == FLOW_RING_STATUS_DELETE_PENDING ||
1009*4882a593Smuzhiyun flow_ring_node->status == FLOW_RING_STATUS_CLOSED) {
1010*4882a593Smuzhiyun *flowid = FLOWID_INVALID;
1011*4882a593Smuzhiyun ret = BCME_ERROR;
1012*4882a593Smuzhiyun } else {
1013*4882a593Smuzhiyun *flowid = id;
1014*4882a593Smuzhiyun ret = BCME_OK;
1015*4882a593Smuzhiyun }
1016*4882a593Smuzhiyun
1017*4882a593Smuzhiyun DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags);
1018*4882a593Smuzhiyun return ret;
1019*4882a593Smuzhiyun } /* Flow Id found in the hash */
1020*4882a593Smuzhiyun } /* dhd_flowid_lookup */
1021*4882a593Smuzhiyun
1022*4882a593Smuzhiyun int
dhd_flowid_find_by_ifidx(dhd_pub_t * dhdp,uint8 ifindex,uint16 flowid)1023*4882a593Smuzhiyun dhd_flowid_find_by_ifidx(dhd_pub_t *dhdp, uint8 ifindex, uint16 flowid)
1024*4882a593Smuzhiyun {
1025*4882a593Smuzhiyun int hashidx = 0;
1026*4882a593Smuzhiyun bool found = FALSE;
1027*4882a593Smuzhiyun flow_hash_info_t *cur;
1028*4882a593Smuzhiyun if_flow_lkup_t *if_flow_lkup;
1029*4882a593Smuzhiyun unsigned long flags;
1030*4882a593Smuzhiyun
1031*4882a593Smuzhiyun if (!dhdp->flow_ring_table) {
1032*4882a593Smuzhiyun DHD_ERROR(("%s : dhd->flow_ring_table is NULL\n", __FUNCTION__));
1033*4882a593Smuzhiyun return BCME_ERROR;
1034*4882a593Smuzhiyun }
1035*4882a593Smuzhiyun
1036*4882a593Smuzhiyun DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
1037*4882a593Smuzhiyun if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
1038*4882a593Smuzhiyun for (hashidx = 0; hashidx < DHD_FLOWRING_HASH_SIZE; hashidx++) {
1039*4882a593Smuzhiyun cur = if_flow_lkup[ifindex].fl_hash[hashidx];
1040*4882a593Smuzhiyun if (cur) {
1041*4882a593Smuzhiyun if (cur->flowid == flowid) {
1042*4882a593Smuzhiyun found = TRUE;
1043*4882a593Smuzhiyun }
1044*4882a593Smuzhiyun
1045*4882a593Smuzhiyun while (!found && cur) {
1046*4882a593Smuzhiyun if (cur->flowid == flowid) {
1047*4882a593Smuzhiyun found = TRUE;
1048*4882a593Smuzhiyun break;
1049*4882a593Smuzhiyun }
1050*4882a593Smuzhiyun cur = cur->next;
1051*4882a593Smuzhiyun }
1052*4882a593Smuzhiyun
1053*4882a593Smuzhiyun if (found) {
1054*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
1055*4882a593Smuzhiyun return BCME_OK;
1056*4882a593Smuzhiyun }
1057*4882a593Smuzhiyun }
1058*4882a593Smuzhiyun }
1059*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
1060*4882a593Smuzhiyun
1061*4882a593Smuzhiyun return BCME_ERROR;
1062*4882a593Smuzhiyun }
1063*4882a593Smuzhiyun
1064*4882a593Smuzhiyun int
dhd_flowid_debug_create(dhd_pub_t * dhdp,uint8 ifindex,uint8 prio,char * sa,char * da,uint16 * flowid)1065*4882a593Smuzhiyun dhd_flowid_debug_create(dhd_pub_t *dhdp, uint8 ifindex,
1066*4882a593Smuzhiyun uint8 prio, char *sa, char *da, uint16 *flowid)
1067*4882a593Smuzhiyun {
1068*4882a593Smuzhiyun return dhd_flowid_lookup(dhdp, ifindex, prio, sa, da, flowid);
1069*4882a593Smuzhiyun }
1070*4882a593Smuzhiyun
1071*4882a593Smuzhiyun /**
1072*4882a593Smuzhiyun * Assign existing or newly created flowid to an 802.3 packet. This flowid is later on used to
1073*4882a593Smuzhiyun * select the flowring to send the packet to the dongle.
1074*4882a593Smuzhiyun */
1075*4882a593Smuzhiyun int
BCMFASTPATH(dhd_flowid_update)1076*4882a593Smuzhiyun BCMFASTPATH(dhd_flowid_update)(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio, void *pktbuf)
1077*4882a593Smuzhiyun {
1078*4882a593Smuzhiyun uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, pktbuf);
1079*4882a593Smuzhiyun struct ether_header *eh = (struct ether_header *)pktdata;
1080*4882a593Smuzhiyun uint16 flowid = 0;
1081*4882a593Smuzhiyun
1082*4882a593Smuzhiyun ASSERT(ifindex < DHD_MAX_IFS);
1083*4882a593Smuzhiyun
1084*4882a593Smuzhiyun if (ifindex >= DHD_MAX_IFS) {
1085*4882a593Smuzhiyun return BCME_BADARG;
1086*4882a593Smuzhiyun }
1087*4882a593Smuzhiyun
1088*4882a593Smuzhiyun if (!dhdp->flowid_allocator) {
1089*4882a593Smuzhiyun DHD_ERROR(("%s: Flow ring not intited yet \n", __FUNCTION__));
1090*4882a593Smuzhiyun return BCME_ERROR;
1091*4882a593Smuzhiyun }
1092*4882a593Smuzhiyun
1093*4882a593Smuzhiyun if (dhd_flowid_lookup(dhdp, ifindex, prio, (char *)eh->ether_shost, (char *)eh->ether_dhost,
1094*4882a593Smuzhiyun &flowid) != BCME_OK) {
1095*4882a593Smuzhiyun return BCME_ERROR;
1096*4882a593Smuzhiyun }
1097*4882a593Smuzhiyun
1098*4882a593Smuzhiyun DHD_FLOWRING_INFO(("%s: prio %d flowid %d\n", __FUNCTION__, prio, flowid));
1099*4882a593Smuzhiyun
1100*4882a593Smuzhiyun /* Tag the packet with flowid */
1101*4882a593Smuzhiyun DHD_PKT_SET_FLOWID(pktbuf, flowid);
1102*4882a593Smuzhiyun return BCME_OK;
1103*4882a593Smuzhiyun }
1104*4882a593Smuzhiyun
1105*4882a593Smuzhiyun static void
dhd_flowid_map_free(dhd_pub_t * dhdp,uint8 ifindex,uint16 flowid)1106*4882a593Smuzhiyun dhd_flowid_map_free(dhd_pub_t *dhdp, uint8 ifindex, uint16 flowid)
1107*4882a593Smuzhiyun {
1108*4882a593Smuzhiyun #if defined(DHD_HTPUT_TUNABLES)
1109*4882a593Smuzhiyun if (dhdp->htput_flowid_allocator) {
1110*4882a593Smuzhiyun if (DHD_IS_FLOWID_HTPUT(dhdp, flowid)) {
1111*4882a593Smuzhiyun id16_map_free(dhdp->htput_flowid_allocator, flowid);
1112*4882a593Smuzhiyun /* decrement htput client counter */
1113*4882a593Smuzhiyun if (DHD_IF_ROLE_MULTI_CLIENT(dhdp, ifindex)) {
1114*4882a593Smuzhiyun dhdp->htput_client_flow_rings--;
1115*4882a593Smuzhiyun }
1116*4882a593Smuzhiyun return;
1117*4882a593Smuzhiyun }
1118*4882a593Smuzhiyun }
1119*4882a593Smuzhiyun #endif /* !DHD_HTPUT_TUNABLES */
1120*4882a593Smuzhiyun
1121*4882a593Smuzhiyun id16_map_free(dhdp->flowid_allocator, flowid);
1122*4882a593Smuzhiyun
1123*4882a593Smuzhiyun return;
1124*4882a593Smuzhiyun }
1125*4882a593Smuzhiyun
1126*4882a593Smuzhiyun void
dhd_flowid_free(dhd_pub_t * dhdp,uint8 ifindex,uint16 flowid)1127*4882a593Smuzhiyun dhd_flowid_free(dhd_pub_t *dhdp, uint8 ifindex, uint16 flowid)
1128*4882a593Smuzhiyun {
1129*4882a593Smuzhiyun int hashix;
1130*4882a593Smuzhiyun bool found = FALSE;
1131*4882a593Smuzhiyun flow_hash_info_t *cur, *prev;
1132*4882a593Smuzhiyun if_flow_lkup_t *if_flow_lkup;
1133*4882a593Smuzhiyun unsigned long flags;
1134*4882a593Smuzhiyun bool if_role_multi_client;
1135*4882a593Smuzhiyun
1136*4882a593Smuzhiyun ASSERT(ifindex < DHD_MAX_IFS);
1137*4882a593Smuzhiyun if (ifindex >= DHD_MAX_IFS)
1138*4882a593Smuzhiyun return;
1139*4882a593Smuzhiyun
1140*4882a593Smuzhiyun DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
1141*4882a593Smuzhiyun if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
1142*4882a593Smuzhiyun
1143*4882a593Smuzhiyun if_role_multi_client = DHD_IF_ROLE_MULTI_CLIENT(dhdp, ifindex);
1144*4882a593Smuzhiyun
1145*4882a593Smuzhiyun for (hashix = 0; hashix < DHD_FLOWRING_HASH_SIZE; hashix++) {
1146*4882a593Smuzhiyun
1147*4882a593Smuzhiyun cur = if_flow_lkup[ifindex].fl_hash[hashix];
1148*4882a593Smuzhiyun
1149*4882a593Smuzhiyun if (cur) {
1150*4882a593Smuzhiyun if (cur->flowid == flowid) {
1151*4882a593Smuzhiyun found = TRUE;
1152*4882a593Smuzhiyun }
1153*4882a593Smuzhiyun
1154*4882a593Smuzhiyun prev = NULL;
1155*4882a593Smuzhiyun while (!found && cur) {
1156*4882a593Smuzhiyun if (cur->flowid == flowid) {
1157*4882a593Smuzhiyun found = TRUE;
1158*4882a593Smuzhiyun break;
1159*4882a593Smuzhiyun }
1160*4882a593Smuzhiyun prev = cur;
1161*4882a593Smuzhiyun cur = cur->next;
1162*4882a593Smuzhiyun }
1163*4882a593Smuzhiyun if (found) {
1164*4882a593Smuzhiyun if (!prev) {
1165*4882a593Smuzhiyun if_flow_lkup[ifindex].fl_hash[hashix] = cur->next;
1166*4882a593Smuzhiyun } else {
1167*4882a593Smuzhiyun prev->next = cur->next;
1168*4882a593Smuzhiyun }
1169*4882a593Smuzhiyun
1170*4882a593Smuzhiyun /* Decrement multi_client_flow_rings */
1171*4882a593Smuzhiyun if (if_role_multi_client) {
1172*4882a593Smuzhiyun dhdp->multi_client_flow_rings--;
1173*4882a593Smuzhiyun }
1174*4882a593Smuzhiyun
1175*4882a593Smuzhiyun /* deregister flowid from dhd_pub. */
1176*4882a593Smuzhiyun dhd_del_flowid(dhdp, ifindex, flowid);
1177*4882a593Smuzhiyun
1178*4882a593Smuzhiyun dhd_flowid_map_free(dhdp, ifindex, flowid);
1179*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
1180*4882a593Smuzhiyun MFREE(dhdp->osh, cur, sizeof(flow_hash_info_t));
1181*4882a593Smuzhiyun
1182*4882a593Smuzhiyun return;
1183*4882a593Smuzhiyun }
1184*4882a593Smuzhiyun }
1185*4882a593Smuzhiyun }
1186*4882a593Smuzhiyun
1187*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
1188*4882a593Smuzhiyun DHD_ERROR(("%s: could not free flow ring hash entry flowid %d\n",
1189*4882a593Smuzhiyun __FUNCTION__, flowid));
1190*4882a593Smuzhiyun } /* dhd_flowid_free */
1191*4882a593Smuzhiyun
1192*4882a593Smuzhiyun /**
1193*4882a593Smuzhiyun * Delete all Flow rings associated with the given interface. Is called when eg the dongle
1194*4882a593Smuzhiyun * indicates that a wireless link has gone down.
1195*4882a593Smuzhiyun */
1196*4882a593Smuzhiyun void
dhd_flow_rings_delete(dhd_pub_t * dhdp,uint8 ifindex)1197*4882a593Smuzhiyun dhd_flow_rings_delete(dhd_pub_t *dhdp, uint8 ifindex)
1198*4882a593Smuzhiyun {
1199*4882a593Smuzhiyun uint32 id;
1200*4882a593Smuzhiyun flow_ring_table_t *flow_ring_table;
1201*4882a593Smuzhiyun
1202*4882a593Smuzhiyun DHD_ERROR(("%s: ifindex %u\n", __FUNCTION__, ifindex));
1203*4882a593Smuzhiyun
1204*4882a593Smuzhiyun ASSERT(ifindex < DHD_MAX_IFS);
1205*4882a593Smuzhiyun if (ifindex >= DHD_MAX_IFS)
1206*4882a593Smuzhiyun return;
1207*4882a593Smuzhiyun
1208*4882a593Smuzhiyun if (!dhdp->flow_ring_table)
1209*4882a593Smuzhiyun return;
1210*4882a593Smuzhiyun
1211*4882a593Smuzhiyun flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table;
1212*4882a593Smuzhiyun for (id = 0; id < dhdp->num_h2d_rings; id++) {
1213*4882a593Smuzhiyun if (flow_ring_table[id].active &&
1214*4882a593Smuzhiyun (flow_ring_table[id].flow_info.ifindex == ifindex) &&
1215*4882a593Smuzhiyun (flow_ring_table[id].status == FLOW_RING_STATUS_OPEN)) {
1216*4882a593Smuzhiyun dhd_bus_flow_ring_delete_request(dhdp->bus,
1217*4882a593Smuzhiyun (void *) &flow_ring_table[id]);
1218*4882a593Smuzhiyun }
1219*4882a593Smuzhiyun }
1220*4882a593Smuzhiyun }
1221*4882a593Smuzhiyun
1222*4882a593Smuzhiyun void
dhd_flow_rings_flush(dhd_pub_t * dhdp,uint8 ifindex)1223*4882a593Smuzhiyun dhd_flow_rings_flush(dhd_pub_t *dhdp, uint8 ifindex)
1224*4882a593Smuzhiyun {
1225*4882a593Smuzhiyun uint32 id;
1226*4882a593Smuzhiyun flow_ring_table_t *flow_ring_table;
1227*4882a593Smuzhiyun
1228*4882a593Smuzhiyun DHD_INFO(("%s: ifindex %u\n", __FUNCTION__, ifindex));
1229*4882a593Smuzhiyun
1230*4882a593Smuzhiyun ASSERT(ifindex < DHD_MAX_IFS);
1231*4882a593Smuzhiyun if (ifindex >= DHD_MAX_IFS)
1232*4882a593Smuzhiyun return;
1233*4882a593Smuzhiyun
1234*4882a593Smuzhiyun if (!dhdp->flow_ring_table)
1235*4882a593Smuzhiyun return;
1236*4882a593Smuzhiyun flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table;
1237*4882a593Smuzhiyun
1238*4882a593Smuzhiyun for (id = 0; id < dhdp->num_h2d_rings; id++) {
1239*4882a593Smuzhiyun if (flow_ring_table[id].active &&
1240*4882a593Smuzhiyun (flow_ring_table[id].flow_info.ifindex == ifindex) &&
1241*4882a593Smuzhiyun (flow_ring_table[id].status == FLOW_RING_STATUS_OPEN)) {
1242*4882a593Smuzhiyun dhd_bus_flow_ring_flush_request(dhdp->bus,
1243*4882a593Smuzhiyun (void *) &flow_ring_table[id]);
1244*4882a593Smuzhiyun }
1245*4882a593Smuzhiyun }
1246*4882a593Smuzhiyun }
1247*4882a593Smuzhiyun
1248*4882a593Smuzhiyun /** Delete flow ring(s) for given peer address. */
1249*4882a593Smuzhiyun void
dhd_flow_rings_delete_for_peer(dhd_pub_t * dhdp,uint8 ifindex,char * addr)1250*4882a593Smuzhiyun dhd_flow_rings_delete_for_peer(dhd_pub_t *dhdp, uint8 ifindex, char *addr)
1251*4882a593Smuzhiyun {
1252*4882a593Smuzhiyun uint32 id;
1253*4882a593Smuzhiyun flow_ring_table_t *flow_ring_table;
1254*4882a593Smuzhiyun
1255*4882a593Smuzhiyun DHD_ERROR(("%s: ifindex %u\n", __FUNCTION__, ifindex));
1256*4882a593Smuzhiyun
1257*4882a593Smuzhiyun ASSERT(ifindex < DHD_MAX_IFS);
1258*4882a593Smuzhiyun if (ifindex >= DHD_MAX_IFS)
1259*4882a593Smuzhiyun return;
1260*4882a593Smuzhiyun
1261*4882a593Smuzhiyun if (!dhdp->flow_ring_table)
1262*4882a593Smuzhiyun return;
1263*4882a593Smuzhiyun
1264*4882a593Smuzhiyun flow_ring_table = (flow_ring_table_t *)dhdp->flow_ring_table;
1265*4882a593Smuzhiyun for (id = 0; id < dhdp->num_h2d_rings; id++) {
1266*4882a593Smuzhiyun /*
1267*4882a593Smuzhiyun * Send flowring delete request even if flowring status is
1268*4882a593Smuzhiyun * FLOW_RING_STATUS_CREATE_PENDING, to handle cases where DISASSOC_IND
1269*4882a593Smuzhiyun * event comes ahead of flowring create response.
1270*4882a593Smuzhiyun * Otherwise the flowring will not be deleted later as there will not be any
1271*4882a593Smuzhiyun * DISASSOC_IND event. With this change, when create response event comes to DHD,
1272*4882a593Smuzhiyun * it will change the status to FLOW_RING_STATUS_OPEN and soon delete response
1273*4882a593Smuzhiyun * event will come, upon which DHD will delete the flowring.
1274*4882a593Smuzhiyun */
1275*4882a593Smuzhiyun if (flow_ring_table[id].active &&
1276*4882a593Smuzhiyun (flow_ring_table[id].flow_info.ifindex == ifindex) &&
1277*4882a593Smuzhiyun (!memcmp(flow_ring_table[id].flow_info.da, addr, ETHER_ADDR_LEN)) &&
1278*4882a593Smuzhiyun ((flow_ring_table[id].status == FLOW_RING_STATUS_OPEN) ||
1279*4882a593Smuzhiyun (flow_ring_table[id].status == FLOW_RING_STATUS_CREATE_PENDING))) {
1280*4882a593Smuzhiyun DHD_ERROR(("%s: deleting flowid %d\n",
1281*4882a593Smuzhiyun __FUNCTION__, flow_ring_table[id].flowid));
1282*4882a593Smuzhiyun dhd_bus_flow_ring_delete_request(dhdp->bus,
1283*4882a593Smuzhiyun (void *) &flow_ring_table[id]);
1284*4882a593Smuzhiyun }
1285*4882a593Smuzhiyun }
1286*4882a593Smuzhiyun }
1287*4882a593Smuzhiyun
1288*4882a593Smuzhiyun /** Handles interface ADD, CHANGE, DEL indications from the dongle */
1289*4882a593Smuzhiyun void
dhd_update_interface_flow_info(dhd_pub_t * dhdp,uint8 ifindex,uint8 op,uint8 role)1290*4882a593Smuzhiyun dhd_update_interface_flow_info(dhd_pub_t *dhdp, uint8 ifindex,
1291*4882a593Smuzhiyun uint8 op, uint8 role)
1292*4882a593Smuzhiyun {
1293*4882a593Smuzhiyun if_flow_lkup_t *if_flow_lkup;
1294*4882a593Smuzhiyun unsigned long flags;
1295*4882a593Smuzhiyun
1296*4882a593Smuzhiyun ASSERT(ifindex < DHD_MAX_IFS);
1297*4882a593Smuzhiyun if (ifindex >= DHD_MAX_IFS)
1298*4882a593Smuzhiyun return;
1299*4882a593Smuzhiyun
1300*4882a593Smuzhiyun DHD_INFO(("%s: ifindex %u op %u role is %u \n",
1301*4882a593Smuzhiyun __FUNCTION__, ifindex, op, role));
1302*4882a593Smuzhiyun if (!dhdp->flowid_allocator) {
1303*4882a593Smuzhiyun DHD_ERROR(("%s: Flow ring not intited yet \n", __FUNCTION__));
1304*4882a593Smuzhiyun return;
1305*4882a593Smuzhiyun }
1306*4882a593Smuzhiyun
1307*4882a593Smuzhiyun DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
1308*4882a593Smuzhiyun if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
1309*4882a593Smuzhiyun
1310*4882a593Smuzhiyun if (op == WLC_E_IF_ADD || op == WLC_E_IF_CHANGE) {
1311*4882a593Smuzhiyun
1312*4882a593Smuzhiyun if_flow_lkup[ifindex].role = role;
1313*4882a593Smuzhiyun
1314*4882a593Smuzhiyun if (role == WLC_E_IF_ROLE_WDS) {
1315*4882a593Smuzhiyun /**
1316*4882a593Smuzhiyun * WDS role does not send WLC_E_LINK event after interface is up.
1317*4882a593Smuzhiyun * So to create flowrings for WDS, make status as TRUE in WLC_E_IF itself.
1318*4882a593Smuzhiyun * same is true while making the status as FALSE.
1319*4882a593Smuzhiyun * TODO: Fix FW to send WLC_E_LINK for WDS role aswell. So that all the
1320*4882a593Smuzhiyun * interfaces are handled uniformly.
1321*4882a593Smuzhiyun */
1322*4882a593Smuzhiyun if_flow_lkup[ifindex].status = TRUE;
1323*4882a593Smuzhiyun DHD_INFO(("%s: Mcast Flow ring for ifindex %d role is %d \n",
1324*4882a593Smuzhiyun __FUNCTION__, ifindex, role));
1325*4882a593Smuzhiyun }
1326*4882a593Smuzhiyun } else if ((op == WLC_E_IF_DEL) && (role == WLC_E_IF_ROLE_WDS)) {
1327*4882a593Smuzhiyun if_flow_lkup[ifindex].status = FALSE;
1328*4882a593Smuzhiyun DHD_INFO(("%s: cleanup all Flow rings for ifindex %d role is %d \n",
1329*4882a593Smuzhiyun __FUNCTION__, ifindex, role));
1330*4882a593Smuzhiyun }
1331*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
1332*4882a593Smuzhiyun }
1333*4882a593Smuzhiyun
1334*4882a593Smuzhiyun /** Handles a STA 'link' indication from the dongle */
1335*4882a593Smuzhiyun int
dhd_update_interface_link_status(dhd_pub_t * dhdp,uint8 ifindex,uint8 status)1336*4882a593Smuzhiyun dhd_update_interface_link_status(dhd_pub_t *dhdp, uint8 ifindex, uint8 status)
1337*4882a593Smuzhiyun {
1338*4882a593Smuzhiyun if_flow_lkup_t *if_flow_lkup;
1339*4882a593Smuzhiyun unsigned long flags;
1340*4882a593Smuzhiyun
1341*4882a593Smuzhiyun ASSERT(ifindex < DHD_MAX_IFS);
1342*4882a593Smuzhiyun if (ifindex >= DHD_MAX_IFS)
1343*4882a593Smuzhiyun return BCME_BADARG;
1344*4882a593Smuzhiyun
1345*4882a593Smuzhiyun DHD_INFO(("%s: ifindex %d status %d\n", __FUNCTION__, ifindex, status));
1346*4882a593Smuzhiyun
1347*4882a593Smuzhiyun DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
1348*4882a593Smuzhiyun if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
1349*4882a593Smuzhiyun
1350*4882a593Smuzhiyun if (status) {
1351*4882a593Smuzhiyun if_flow_lkup[ifindex].status = TRUE;
1352*4882a593Smuzhiyun } else {
1353*4882a593Smuzhiyun if_flow_lkup[ifindex].status = FALSE;
1354*4882a593Smuzhiyun }
1355*4882a593Smuzhiyun
1356*4882a593Smuzhiyun DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
1357*4882a593Smuzhiyun
1358*4882a593Smuzhiyun return BCME_OK;
1359*4882a593Smuzhiyun }
1360*4882a593Smuzhiyun
1361*4882a593Smuzhiyun /** Update flow priority mapping, called on IOVAR */
dhd_update_flow_prio_map(dhd_pub_t * dhdp,uint8 map)1362*4882a593Smuzhiyun int dhd_update_flow_prio_map(dhd_pub_t *dhdp, uint8 map)
1363*4882a593Smuzhiyun {
1364*4882a593Smuzhiyun uint16 flowid;
1365*4882a593Smuzhiyun flow_ring_node_t *flow_ring_node;
1366*4882a593Smuzhiyun
1367*4882a593Smuzhiyun if (map > DHD_FLOW_PRIO_LLR_MAP)
1368*4882a593Smuzhiyun return BCME_BADOPTION;
1369*4882a593Smuzhiyun
1370*4882a593Smuzhiyun /* Check if we need to change prio map */
1371*4882a593Smuzhiyun if (map == dhdp->flow_prio_map_type)
1372*4882a593Smuzhiyun return BCME_OK;
1373*4882a593Smuzhiyun
1374*4882a593Smuzhiyun /* If any ring is active we cannot change priority mapping for flow rings */
1375*4882a593Smuzhiyun for (flowid = 0; flowid < dhdp->num_h2d_rings; flowid++) {
1376*4882a593Smuzhiyun flow_ring_node = DHD_FLOW_RING(dhdp, flowid);
1377*4882a593Smuzhiyun if (flow_ring_node->active)
1378*4882a593Smuzhiyun return BCME_EPERM;
1379*4882a593Smuzhiyun }
1380*4882a593Smuzhiyun
1381*4882a593Smuzhiyun /* Inform firmware about new mapping type */
1382*4882a593Smuzhiyun if (BCME_OK != dhd_flow_prio_map(dhdp, &map, TRUE))
1383*4882a593Smuzhiyun return BCME_ERROR;
1384*4882a593Smuzhiyun
1385*4882a593Smuzhiyun /* update internal structures */
1386*4882a593Smuzhiyun dhdp->flow_prio_map_type = map;
1387*4882a593Smuzhiyun if (dhdp->flow_prio_map_type == DHD_FLOW_PRIO_TID_MAP)
1388*4882a593Smuzhiyun bcopy(prio2tid, dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO);
1389*4882a593Smuzhiyun else
1390*4882a593Smuzhiyun bcopy(prio2ac, dhdp->flow_prio_map, sizeof(uint8) * NUMPRIO);
1391*4882a593Smuzhiyun
1392*4882a593Smuzhiyun dhdp->max_multi_client_flow_rings = dhd_get_max_multi_client_flow_rings(dhdp);
1393*4882a593Smuzhiyun
1394*4882a593Smuzhiyun return BCME_OK;
1395*4882a593Smuzhiyun }
1396*4882a593Smuzhiyun
1397*4882a593Smuzhiyun /** Inform firmware on updated flow priority mapping, called on IOVAR */
dhd_flow_prio_map(dhd_pub_t * dhd,uint8 * map,bool set)1398*4882a593Smuzhiyun int dhd_flow_prio_map(dhd_pub_t *dhd, uint8 *map, bool set)
1399*4882a593Smuzhiyun {
1400*4882a593Smuzhiyun uint8 iovbuf[WLC_IOCTL_SMLEN];
1401*4882a593Smuzhiyun int len;
1402*4882a593Smuzhiyun uint32 val;
1403*4882a593Smuzhiyun if (!set) {
1404*4882a593Smuzhiyun bzero(&iovbuf, sizeof(iovbuf));
1405*4882a593Smuzhiyun len = bcm_mkiovar("bus:fl_prio_map", NULL, 0, (char*)iovbuf, sizeof(iovbuf));
1406*4882a593Smuzhiyun if (len == 0) {
1407*4882a593Smuzhiyun return BCME_BUFTOOSHORT;
1408*4882a593Smuzhiyun }
1409*4882a593Smuzhiyun if (dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iovbuf, sizeof(iovbuf), FALSE, 0) < 0) {
1410*4882a593Smuzhiyun DHD_ERROR(("%s: failed to get fl_prio_map\n", __FUNCTION__));
1411*4882a593Smuzhiyun return BCME_ERROR;
1412*4882a593Smuzhiyun }
1413*4882a593Smuzhiyun *map = iovbuf[0];
1414*4882a593Smuzhiyun return BCME_OK;
1415*4882a593Smuzhiyun }
1416*4882a593Smuzhiyun val = (uint32)map[0];
1417*4882a593Smuzhiyun len = bcm_mkiovar("bus:fl_prio_map", (char *)&val, sizeof(val),
1418*4882a593Smuzhiyun (char*)iovbuf, sizeof(iovbuf));
1419*4882a593Smuzhiyun if (len == 0) {
1420*4882a593Smuzhiyun return BCME_BUFTOOSHORT;
1421*4882a593Smuzhiyun }
1422*4882a593Smuzhiyun if (dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, len, TRUE, 0) < 0) {
1423*4882a593Smuzhiyun DHD_ERROR(("%s: failed to set fl_prio_map \n",
1424*4882a593Smuzhiyun __FUNCTION__));
1425*4882a593Smuzhiyun return BCME_ERROR;
1426*4882a593Smuzhiyun }
1427*4882a593Smuzhiyun return BCME_OK;
1428*4882a593Smuzhiyun }
1429*4882a593Smuzhiyun
1430*4882a593Smuzhiyun uint32
dhd_active_tx_flowring_bkpq_len(dhd_pub_t * dhd)1431*4882a593Smuzhiyun dhd_active_tx_flowring_bkpq_len(dhd_pub_t *dhd)
1432*4882a593Smuzhiyun {
1433*4882a593Smuzhiyun unsigned long list_lock_flags;
1434*4882a593Smuzhiyun dll_t *item, *prev;
1435*4882a593Smuzhiyun flow_ring_node_t *flow_ring_node;
1436*4882a593Smuzhiyun dhd_bus_t *bus = dhd->bus;
1437*4882a593Smuzhiyun uint32 active_tx_flowring_qlen = 0;
1438*4882a593Smuzhiyun
1439*4882a593Smuzhiyun DHD_FLOWRING_LIST_LOCK(bus->dhd->flowring_list_lock, list_lock_flags);
1440*4882a593Smuzhiyun
1441*4882a593Smuzhiyun for (item = dll_tail_p(&bus->flowring_active_list);
1442*4882a593Smuzhiyun !dll_end(&bus->flowring_active_list, item); item = prev) {
1443*4882a593Smuzhiyun
1444*4882a593Smuzhiyun prev = dll_prev_p(item);
1445*4882a593Smuzhiyun
1446*4882a593Smuzhiyun flow_ring_node = dhd_constlist_to_flowring(item);
1447*4882a593Smuzhiyun if (flow_ring_node->active) {
1448*4882a593Smuzhiyun DHD_INFO(("%s :%d\n", __FUNCTION__, flow_ring_node->queue.len));
1449*4882a593Smuzhiyun active_tx_flowring_qlen += flow_ring_node->queue.len;
1450*4882a593Smuzhiyun }
1451*4882a593Smuzhiyun }
1452*4882a593Smuzhiyun DHD_FLOWRING_LIST_UNLOCK(bus->dhd->flowring_list_lock, list_lock_flags);
1453*4882a593Smuzhiyun return active_tx_flowring_qlen;
1454*4882a593Smuzhiyun }
1455*4882a593Smuzhiyun
1456*4882a593Smuzhiyun #ifdef DHD_AWDL
1457*4882a593Smuzhiyun /**
1458*4882a593Smuzhiyun * Handle/Intercept awdl peer op IOVAR fired by user
1459*4882a593Smuzhiyun * buf = NULL means delete all peers in awdl interface
1460*4882a593Smuzhiyun */
1461*4882a593Smuzhiyun void
dhd_awdl_peer_op(dhd_pub_t * dhdp,uint8 ifindex,void * buf,uint32 buflen)1462*4882a593Smuzhiyun dhd_awdl_peer_op(dhd_pub_t *dhdp, uint8 ifindex, void *buf, uint32 buflen)
1463*4882a593Smuzhiyun {
1464*4882a593Smuzhiyun awdl_peer_op_t *peer = (awdl_peer_op_t *)buf;
1465*4882a593Smuzhiyun DHD_TRACE(("%s\n", __FUNCTION__));
1466*4882a593Smuzhiyun
1467*4882a593Smuzhiyun ASSERT(ifindex < DHD_MAX_IFS);
1468*4882a593Smuzhiyun if (ifindex >= DHD_MAX_IFS)
1469*4882a593Smuzhiyun return;
1470*4882a593Smuzhiyun if (!buf) {
1471*4882a593Smuzhiyun /* Delete all peers in awdl interface */
1472*4882a593Smuzhiyun if_flow_lkup_t *if_flow_lkup;
1473*4882a593Smuzhiyun if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
1474*4882a593Smuzhiyun if (if_flow_lkup[ifindex].role != WLC_E_IF_ROLE_AWDL) {
1475*4882a593Smuzhiyun DHD_ERROR(("%s: Iinterface %d is not a awdl peer \n",
1476*4882a593Smuzhiyun __FUNCTION__, ifindex));
1477*4882a593Smuzhiyun return;
1478*4882a593Smuzhiyun }
1479*4882a593Smuzhiyun dhd_flow_rings_delete(dhdp, ifindex);
1480*4882a593Smuzhiyun return;
1481*4882a593Smuzhiyun }
1482*4882a593Smuzhiyun /* Parse awdl_peer_op info now */
1483*4882a593Smuzhiyun if (buflen < sizeof(awdl_peer_op_t)) {
1484*4882a593Smuzhiyun DHD_ERROR(("%s: cannot handle awdl_peer_op add/del\n", __FUNCTION__));
1485*4882a593Smuzhiyun return;
1486*4882a593Smuzhiyun }
1487*4882a593Smuzhiyun /**
1488*4882a593Smuzhiyun * Only flowring deletion is handled here
1489*4882a593Smuzhiyun * Flowring addition is taken care in dhd_flowid_lookup
1490*4882a593Smuzhiyun */
1491*4882a593Smuzhiyun if (peer->opcode == AWDL_PEER_OP_DEL) {
1492*4882a593Smuzhiyun dhd_del_sta(dhdp, ifindex, &peer->addr.octet[0]);
1493*4882a593Smuzhiyun dhd_flow_rings_delete_for_peer(dhdp, ifindex, (char *)&peer->addr.octet[0]);
1494*4882a593Smuzhiyun } else if (peer->opcode == AWDL_PEER_OP_ADD) {
1495*4882a593Smuzhiyun dhd_findadd_sta(dhdp, ifindex, &peer->addr.octet[0]);
1496*4882a593Smuzhiyun }
1497*4882a593Smuzhiyun return;
1498*4882a593Smuzhiyun }
1499*4882a593Smuzhiyun #endif /* DHD_AWDL */
1500