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