2 * @file Header file describing the flow rings DHD interfaces.
4 * Flow rings are transmit traffic (=propagating towards antenna) related entities.
6 * Provides type definitions and function prototypes used to create, delete and manage flow rings at
9 * Copyright (C) 1999-2016, Broadcom Corporation
11 * Unless you and Broadcom execute a separate written software license
12 * agreement governing use of this software, this software is licensed to you
13 * under the terms of the GNU General Public License version 2 (the "GPL"),
14 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
15 * following added to such license:
17 * As a special exception, the copyright holders of this software give you
18 * permission to link this software with independent modules, and to copy and
19 * distribute the resulting executable under terms of your choice, provided that
20 * you also meet, for each linked independent module, the terms and conditions of
21 * the license of that module. An independent module is a module which is not
22 * derived from this software. The special exception does not apply to any
23 * modifications of the software.
25 * Notwithstanding the above, under no circumstances may you combine this
26 * software in any way with any other Broadcom software provided under a license
27 * other than the GPL, without Broadcom's express prior written consent.
30 * <<Broadcom-WL-IPTag/Open:>>
32 * $Id: dhd_flowring.h 591285 2015-10-07 11:56:29Z $
40 #ifndef _dhd_flowrings_h_
41 #define _dhd_flowrings_h_
43 /* Max pkts held in a flow ring's backup queue */
44 #define FLOW_RING_QUEUE_THRESHOLD (2048)
46 /* Number of H2D common rings */
47 #define FLOW_RING_COMMON BCMPCIE_H2D_COMMON_MSGRINGS
49 #define FLOWID_INVALID (ID16_INVALID)
50 #define FLOWID_RESERVED (FLOW_RING_COMMON)
52 #define FLOW_RING_STATUS_OPEN 0
53 #define FLOW_RING_STATUS_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 #define FLOW_RING_STATUS_STA_FREEING 5
59 #define DHD_FLOWRING_RX_BUFPOST_PKTSZ 2048
61 #define DHD_FLOW_PRIO_AC_MAP 0
62 #define DHD_FLOW_PRIO_TID_MAP 1
63 #define DHD_FLOW_PRIO_LLR_MAP 2
65 /* Pkttag not compatible with PROP_TXSTATUS or WLFC */
66 typedef struct dhd_pkttag_fr {
75 #define DHD_PKTTAG_SET_FLOWID(tag, flow) ((tag)->flowid = (uint16)(flow))
76 #define DHD_PKTTAG_SET_IFID(tag, idx) ((tag)->ifid = (uint16)(idx))
77 #define DHD_PKTTAG_SET_DATAOFF(tag, offset) ((tag)->dataoff = (int)(offset))
78 #define DHD_PKTTAG_SET_PA(tag, pa) ((tag)->physaddr = (pa))
79 #define DHD_PKTTAG_SET_PA_LEN(tag, palen) ((tag)->pa_len = (palen))
81 #define DHD_PKTTAG_FLOWID(tag) ((tag)->flowid)
82 #define DHD_PKTTAG_IFID(tag) ((tag)->ifid)
83 #define DHD_PKTTAG_DATAOFF(tag) ((tag)->dataoff)
84 #define DHD_PKTTAG_PA(tag) ((tag)->physaddr)
85 #define DHD_PKTTAG_PA_LEN(tag) ((tag)->pa_len)
87 /* Hashing a MacAddress for lkup into a per interface flow hash table */
88 #define DHD_FLOWRING_HASH_SIZE 256
89 #define DHD_FLOWRING_HASHINDEX(ea, prio) \
90 ((((uint8 *)(ea))[3] ^ ((uint8 *)(ea))[4] ^ ((uint8 *)(ea))[5] ^ ((uint8)(prio))) \
91 % DHD_FLOWRING_HASH_SIZE)
93 #define DHD_IF_ROLE(pub, idx) (((if_flow_lkup_t *)(pub)->if_flow_lkup)[idx].role)
94 #define DHD_IF_ROLE_AP(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_AP)
95 #define DHD_IF_ROLE_STA(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_STA)
96 #define DHD_IF_ROLE_P2PGO(pub, idx) (DHD_IF_ROLE(pub, idx) == WLC_E_IF_ROLE_P2P_GO)
97 #define DHD_FLOW_RING(dhdp, flowid) \
98 (flow_ring_node_t *)&(((flow_ring_node_t *)((dhdp)->flow_ring_table))[flowid])
102 /* Flow Ring Queue Enqueue overflow callback */
103 typedef int (*flow_queue_cb_t)(struct flow_queue * queue, void * pkt);
106 * Each flow ring has an associated (tx flow controlled) queue. 802.3 packets are transferred
107 * between queue and ring. A packet from the host stack is first added to the queue, and in a later
108 * stage transferred to the flow ring. Packets in the queue are dhd owned, whereas packets in the
109 * flow ring are device owned.
111 typedef struct flow_queue {
112 dll_t list; /* manage a flowring queue in a double linked list */
113 void * head; /* first packet in the queue */
114 void * tail; /* last packet in the queue */
115 uint16 len; /* number of packets in the queue */
116 uint16 max; /* maximum or min budget (used in cumm) */
117 uint32 threshold; /* parent's cummulative length threshold */
118 void * clen_ptr; /* parent's cummulative length counter */
119 uint32 failures; /* enqueue failures due to queue overflow */
120 flow_queue_cb_t cb; /* callback invoked on threshold crossing */
123 #define DHD_FLOW_QUEUE_LEN(queue) ((int)(queue)->len)
124 #define DHD_FLOW_QUEUE_MAX(queue) ((int)(queue)->max)
125 #define DHD_FLOW_QUEUE_THRESHOLD(queue) ((int)(queue)->threshold)
126 #define DHD_FLOW_QUEUE_EMPTY(queue) ((queue)->len == 0)
127 #define DHD_FLOW_QUEUE_FAILURES(queue) ((queue)->failures)
129 #define DHD_FLOW_QUEUE_AVAIL(queue) ((int)((queue)->max - (queue)->len))
130 #define DHD_FLOW_QUEUE_FULL(queue) ((queue)->len >= (queue)->max)
132 #define DHD_FLOW_QUEUE_OVFL(queue, budget) \
133 (((queue)->len) > budget)
135 #define DHD_FLOW_QUEUE_SET_MAX(queue, budget) \
136 ((queue)->max) = ((budget) - 1)
138 /* Queue's cummulative threshold. */
139 #define DHD_FLOW_QUEUE_SET_THRESHOLD(queue, cumm_threshold) \
140 ((queue)->threshold) = ((cumm_threshold) - 1)
142 /* Queue's cummulative length object accessor. */
143 #define DHD_FLOW_QUEUE_CLEN_PTR(queue) ((queue)->clen_ptr)
145 /* Set a queue's cumm_len point to a parent's cumm_ctr_t cummulative length */
146 #define DHD_FLOW_QUEUE_SET_CLEN(queue, parent_clen_ptr) \
147 ((queue)->clen_ptr) = (void *)(parent_clen_ptr)
149 /* see wlfc_proto.h for tx status details */
150 #define DHD_FLOWRING_MAXSTATUS_MSGS 5
151 #define DHD_FLOWRING_TXSTATUS_CNT_UPDATE(bus, flowid, txstatus)
152 /** each flow ring is dedicated to a tid/sa/da combination */
153 typedef struct flow_info {
156 char sa[ETHER_ADDR_LEN];
157 char da[ETHER_ADDR_LEN];
160 /** a flow ring is used for outbound (towards antenna) 802.3 packets */
161 typedef struct flow_ring_node {
162 dll_t list; /* manage a constructed flowring in a dll, must be at first place */
163 flow_queue_t queue; /* queues packets before they enter the flow ring, flow control */
167 * flowid: unique ID of a flow ring, which can either be unicast or broadcast/multicast. For
168 * unicast flow rings, the flow id accelerates ARM 802.3->802.11 header translation.
171 flow_info_t flow_info;
173 void *lock; /* lock for flowring access protection */
176 typedef flow_ring_node_t flow_ring_table_t;
178 typedef struct flow_hash_info {
180 flow_info_t flow_info;
181 struct flow_hash_info *next;
184 typedef struct if_flow_lkup {
186 uint8 role; /* Interface role: STA/AP */
187 flow_hash_info_t *fl_hash[DHD_FLOWRING_HASH_SIZE]; /* Lkup Hash table */
190 static INLINE flow_ring_node_t *
191 dhd_constlist_to_flowring(dll_t *item)
193 return ((flow_ring_node_t *)item);
198 /* Flow ring's queue management functions */
199 extern flow_ring_node_t * dhd_flow_ring_node(dhd_pub_t *dhdp, uint16 flowid);
200 extern flow_queue_t * dhd_flow_queue(dhd_pub_t *dhdp, uint16 flowid);
202 extern void dhd_flow_queue_init(dhd_pub_t *dhdp, flow_queue_t *queue, int max);
203 extern void dhd_flow_queue_register(flow_queue_t *queue, flow_queue_cb_t cb);
204 extern int dhd_flow_queue_enqueue(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt);
205 extern void * dhd_flow_queue_dequeue(dhd_pub_t *dhdp, flow_queue_t *queue);
206 extern void dhd_flow_queue_reinsert(dhd_pub_t *dhdp, flow_queue_t *queue, void *pkt);
208 extern void dhd_flow_ring_config_thresholds(dhd_pub_t *dhdp, uint16 flowid,
209 int queue_budget, int cumm_threshold, void *cumm_ctr);
210 extern int dhd_flow_rings_init(dhd_pub_t *dhdp, uint32 num_flow_rings);
212 extern void dhd_flow_rings_deinit(dhd_pub_t *dhdp);
214 extern int dhd_flowid_update(dhd_pub_t *dhdp, uint8 ifindex, uint8 prio,
217 extern void dhd_flowid_free(dhd_pub_t *dhdp, uint8 ifindex, uint16 flowid);
219 extern void dhd_flow_rings_delete(dhd_pub_t *dhdp, uint8 ifindex);
221 extern void dhd_flow_rings_delete_for_peer(dhd_pub_t *dhdp, uint8 ifindex,
224 /* Handle Interface ADD, DEL operations */
225 extern void dhd_update_interface_flow_info(dhd_pub_t *dhdp, uint8 ifindex,
226 uint8 op, uint8 role);
228 /* Handle a STA interface link status update */
229 extern int dhd_update_interface_link_status(dhd_pub_t *dhdp, uint8 ifindex,
231 extern int dhd_flow_prio_map(dhd_pub_t *dhd, uint8 *map, bool set);
232 extern int dhd_update_flow_prio_map(dhd_pub_t *dhdp, uint8 map);
234 extern uint8 dhd_flow_rings_ifindex2role(dhd_pub_t *dhdp, uint8 ifindex);
235 #endif /* _dhd_flowrings_h_ */