1 /* 2 * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #include <qdf_module.h> 21 #include "hal_be_api.h" 22 #include "hal_be_hw_headers.h" 23 #include "hal_be_reo.h" 24 #include "hal_tx.h" //HAL_SET_FLD 25 #include "hal_be_rx.h" //HAL_RX_BUF_RBM_GET 26 #include "rx_reo_queue_1k.h" 27 #include "hal_be_rx_tlv.h" 28 29 /* 30 * The 4 bits REO destination ring value is defined as: 0: TCL 31 * 1:SW1 2:SW2 3:SW3 4:SW4 5:Release 6:FW(WIFI) 7:SW5 32 * 8:SW6 9:SW7 10:SW8 11: NOT_USED. 33 * 34 */ 35 uint32_t reo_dest_ring_remap[] = {REO_REMAP_SW1, REO_REMAP_SW2, 36 REO_REMAP_SW3, REO_REMAP_SW4, 37 REO_REMAP_SW5, REO_REMAP_SW6, 38 REO_REMAP_SW7, REO_REMAP_SW8}; 39 /* 40 * WBM idle link descriptor for Return Buffer Manager in case of 41 * multi-chip configuration. 42 */ 43 #define HAL_NUM_CHIPS 4 44 #define HAL_WBM_CHIP_INVALID 0 45 #define HAL_WBM_CHIP0_IDLE_DESC_MAP 1 46 #define HAL_WBM_CHIP1_IDLE_DESC_MAP 2 47 #define HAL_WBM_CHIP2_IDLE_DESC_MAP 3 48 #define HAL_WBM_CHIP3_IDLE_DESC_MAP 12 49 50 uint8_t wbm_idle_link_bm_map[] = {HAL_WBM_CHIP0_IDLE_DESC_MAP, 51 HAL_WBM_CHIP1_IDLE_DESC_MAP, 52 HAL_WBM_CHIP2_IDLE_DESC_MAP, 53 HAL_WBM_CHIP3_IDLE_DESC_MAP}; 54 55 #if defined(QDF_BIG_ENDIAN_MACHINE) 56 void hal_setup_reo_swap(struct hal_soc *soc) 57 { 58 uint32_t reg_val; 59 60 reg_val = HAL_REG_READ(soc, HWIO_REO_R0_CACHE_CTL_CONFIG_ADDR( 61 REO_REG_REG_BASE)); 62 63 reg_val |= HAL_SM(HWIO_REO_R0_CACHE_CTL_CONFIG, WRITE_STRUCT_SWAP, 1); 64 reg_val |= HAL_SM(HWIO_REO_R0_CACHE_CTL_CONFIG, READ_STRUCT_SWAP, 1); 65 66 HAL_REG_WRITE(soc, HWIO_REO_R0_CACHE_CTL_CONFIG_ADDR( 67 REO_REG_REG_BASE), reg_val); 68 } 69 #else 70 void hal_setup_reo_swap(struct hal_soc *soc) 71 { 72 } 73 #endif 74 75 /** 76 * hal_tx_init_data_ring_be() - Initialize all the TCL Descriptors in SRNG 77 * @hal_soc_hdl: Handle to HAL SoC structure 78 * @hal_ring_hdl: Handle to HAL SRNG structure 79 * 80 * Return: none 81 */ 82 static void 83 hal_tx_init_data_ring_be(hal_soc_handle_t hal_soc_hdl, 84 hal_ring_handle_t hal_ring_hdl) 85 { 86 } 87 88 void hal_reo_setup_generic_be(struct hal_soc *soc, void *reoparams, 89 int qref_reset) 90 { 91 uint32_t reg_val; 92 struct hal_reo_params *reo_params = (struct hal_reo_params *)reoparams; 93 94 reg_val = HAL_REG_READ(soc, HWIO_REO_R0_GENERAL_ENABLE_ADDR( 95 REO_REG_REG_BASE)); 96 97 hal_reo_config(soc, reg_val, reo_params); 98 /* Other ring enable bits and REO_ENABLE will be set by FW */ 99 100 /* TODO: Setup destination ring mapping if enabled */ 101 102 /* TODO: Error destination ring setting is left to default. 103 * Default setting is to send all errors to release ring. 104 */ 105 106 /* Set the reo descriptor swap bits in case of BIG endian platform */ 107 hal_setup_reo_swap(soc); 108 109 HAL_REG_WRITE(soc, 110 HWIO_REO_R0_AGING_THRESHOLD_IX_0_ADDR(REO_REG_REG_BASE), 111 HAL_DEFAULT_BE_BK_VI_REO_TIMEOUT_MS * 1000); 112 113 HAL_REG_WRITE(soc, 114 HWIO_REO_R0_AGING_THRESHOLD_IX_1_ADDR(REO_REG_REG_BASE), 115 (HAL_DEFAULT_BE_BK_VI_REO_TIMEOUT_MS * 1000)); 116 117 HAL_REG_WRITE(soc, 118 HWIO_REO_R0_AGING_THRESHOLD_IX_2_ADDR(REO_REG_REG_BASE), 119 (HAL_DEFAULT_BE_BK_VI_REO_TIMEOUT_MS * 1000)); 120 121 HAL_REG_WRITE(soc, 122 HWIO_REO_R0_AGING_THRESHOLD_IX_3_ADDR(REO_REG_REG_BASE), 123 (HAL_DEFAULT_VO_REO_TIMEOUT_MS * 1000)); 124 125 /* 126 * When hash based routing is enabled, routing of the rx packet 127 * is done based on the following value: 1 _ _ _ _ The last 4 128 * bits are based on hash[3:0]. This means the possible values 129 * are 0x10 to 0x1f. This value is used to look-up the 130 * ring ID configured in Destination_Ring_Ctrl_IX_* register. 131 * The Destination_Ring_Ctrl_IX_2 and Destination_Ring_Ctrl_IX_3 132 * registers need to be configured to set-up the 16 entries to 133 * map the hash values to a ring number. There are 3 bits per 134 * hash entry which are mapped as follows: 135 * 0: TCL, 1:SW1, 2:SW2, * 3:SW3, 4:SW4, 5:Release, 6:FW(WIFI), 136 * 7: NOT_USED. 137 */ 138 if (reo_params->rx_hash_enabled) { 139 HAL_REG_WRITE(soc, 140 HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_ADDR( 141 REO_REG_REG_BASE), 142 reo_params->remap1); 143 144 hal_debug("HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_ADDR 0x%x", 145 HAL_REG_READ(soc, 146 HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_ADDR( 147 REO_REG_REG_BASE))); 148 149 HAL_REG_WRITE(soc, 150 HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_ADDR( 151 REO_REG_REG_BASE), 152 reo_params->remap2); 153 154 hal_debug("HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_ADDR 0x%x", 155 HAL_REG_READ(soc, 156 HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_ADDR( 157 REO_REG_REG_BASE))); 158 } 159 160 /* TODO: Check if the following registers shoould be setup by host: 161 * AGING_CONTROL 162 * HIGH_MEMORY_THRESHOLD 163 * GLOBAL_LINK_DESC_COUNT_THRESH_IX_0[1,2] 164 * GLOBAL_LINK_DESC_COUNT_CTRL 165 */ 166 } 167 168 void hal_set_link_desc_addr_be(void *desc, uint32_t cookie, 169 qdf_dma_addr_t link_desc_paddr, 170 uint8_t bm_id) 171 { 172 uint32_t *buf_addr = (uint32_t *)desc; 173 174 HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO, BUFFER_ADDR_31_0, 175 link_desc_paddr & 0xffffffff); 176 HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO, BUFFER_ADDR_39_32, 177 (uint64_t)link_desc_paddr >> 32); 178 HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO, RETURN_BUFFER_MANAGER, 179 bm_id); 180 HAL_DESC_SET_FIELD(buf_addr, BUFFER_ADDR_INFO, SW_BUFFER_COOKIE, 181 cookie); 182 } 183 184 static uint16_t hal_get_rx_max_ba_window_be(int tid) 185 { 186 return HAL_RX_BA_WINDOW_256; 187 } 188 189 static uint32_t hal_get_reo_qdesc_size_be(uint32_t ba_window_size, int tid) 190 { 191 /* Hardcode the ba_window_size to HAL_RX_MAX_BA_WINDOW for 192 * NON_QOS_TID until HW issues are resolved. 193 */ 194 if (tid != HAL_NON_QOS_TID) 195 ba_window_size = hal_get_rx_max_ba_window_be(tid); 196 197 /* Return descriptor size corresponding to window size of 2 since 198 * we set ba_window_size to 2 while setting up REO descriptors as 199 * a WAR to get 2k jump exception aggregates are received without 200 * a BA session. 201 */ 202 if (ba_window_size <= 1) { 203 if (tid != HAL_NON_QOS_TID) 204 return sizeof(struct rx_reo_queue) + 205 sizeof(struct rx_reo_queue_ext); 206 else 207 return sizeof(struct rx_reo_queue); 208 } 209 210 if (ba_window_size <= 105) 211 return sizeof(struct rx_reo_queue) + 212 sizeof(struct rx_reo_queue_ext); 213 214 if (ba_window_size <= 210) 215 return sizeof(struct rx_reo_queue) + 216 (2 * sizeof(struct rx_reo_queue_ext)); 217 218 return sizeof(struct rx_reo_queue) + 219 (3 * sizeof(struct rx_reo_queue_ext)); 220 } 221 222 void *hal_rx_msdu_ext_desc_info_get_ptr_be(void *msdu_details_ptr) 223 { 224 return HAL_RX_MSDU_EXT_DESC_INFO_GET(msdu_details_ptr); 225 } 226 227 #if defined(QCA_WIFI_KIWI) && !defined(QCA_WIFI_KIWI_V2) 228 static inline uint32_t 229 hal_wbm2sw_release_source_get(void *hal_desc, enum hal_be_wbm_release_dir dir) 230 { 231 uint32_t buf_src; 232 233 buf_src = HAL_WBM2SW_RELEASE_SRC_GET(hal_desc); 234 switch (buf_src) { 235 case HAL_BE_RX_WBM_ERR_SRC_RXDMA: 236 return HAL_RX_WBM_ERR_SRC_RXDMA; 237 case HAL_BE_RX_WBM_ERR_SRC_REO: 238 return HAL_RX_WBM_ERR_SRC_REO; 239 case HAL_BE_RX_WBM_ERR_SRC_FW_RX: 240 if (dir != HAL_BE_WBM_RELEASE_DIR_RX) 241 qdf_assert_always(0); 242 return HAL_RX_WBM_ERR_SRC_FW; 243 case HAL_BE_RX_WBM_ERR_SRC_SW_RX: 244 if (dir != HAL_BE_WBM_RELEASE_DIR_RX) 245 qdf_assert_always(0); 246 return HAL_RX_WBM_ERR_SRC_SW; 247 case HAL_BE_RX_WBM_ERR_SRC_TQM: 248 return HAL_RX_WBM_ERR_SRC_TQM; 249 case HAL_BE_RX_WBM_ERR_SRC_FW_TX: 250 if (dir != HAL_BE_WBM_RELEASE_DIR_TX) 251 qdf_assert_always(0); 252 return HAL_RX_WBM_ERR_SRC_FW; 253 case HAL_BE_RX_WBM_ERR_SRC_SW_TX: 254 if (dir != HAL_BE_WBM_RELEASE_DIR_TX) 255 qdf_assert_always(0); 256 return HAL_RX_WBM_ERR_SRC_SW; 257 default: 258 qdf_assert_always(0); 259 } 260 261 return buf_src; 262 } 263 #else 264 static inline uint32_t 265 hal_wbm2sw_release_source_get(void *hal_desc, enum hal_be_wbm_release_dir dir) 266 { 267 return HAL_WBM2SW_RELEASE_SRC_GET(hal_desc); 268 } 269 #endif 270 271 uint32_t hal_tx_comp_get_buffer_source_generic_be(void *hal_desc) 272 { 273 return hal_wbm2sw_release_source_get(hal_desc, 274 HAL_BE_WBM_RELEASE_DIR_TX); 275 } 276 277 /** 278 * hal_tx_comp_get_release_reason_generic_be() - TQM Release reason 279 * @hal_desc: completion ring descriptor pointer 280 * 281 * This function will return the type of pointer - buffer or descriptor 282 * 283 * Return: buffer type 284 */ 285 static uint8_t hal_tx_comp_get_release_reason_generic_be(void *hal_desc) 286 { 287 uint32_t comp_desc = *(uint32_t *)(((uint8_t *)hal_desc) + 288 WBM2SW_COMPLETION_RING_TX_TQM_RELEASE_REASON_OFFSET); 289 290 return (comp_desc & 291 WBM2SW_COMPLETION_RING_TX_TQM_RELEASE_REASON_MASK) >> 292 WBM2SW_COMPLETION_RING_TX_TQM_RELEASE_REASON_LSB; 293 } 294 295 /** 296 * hal_get_wbm_internal_error_generic_be() - is WBM internal error 297 * @hal_desc: completion ring descriptor pointer 298 * 299 * This function will return 0 or 1 - is it WBM internal error or not 300 * 301 * Return: uint8_t 302 */ 303 static uint8_t hal_get_wbm_internal_error_generic_be(void *hal_desc) 304 { 305 /* 306 * TODO - This func is called by tx comp and wbm error handler 307 * Check if one needs to use WBM2SW-TX and other WBM2SW-RX 308 */ 309 uint32_t comp_desc = 310 *(uint32_t *)(((uint8_t *)hal_desc) + 311 HAL_WBM_INTERNAL_ERROR_OFFSET); 312 313 return (comp_desc & HAL_WBM_INTERNAL_ERROR_MASK) >> 314 HAL_WBM_INTERNAL_ERROR_LSB; 315 } 316 317 /** 318 * hal_rx_wbm_err_src_get_be() - Get WBM error source from descriptor 319 * @ring_desc: ring descriptor 320 * 321 * Return: wbm error source 322 */ 323 static uint32_t hal_rx_wbm_err_src_get_be(hal_ring_desc_t ring_desc) 324 { 325 return hal_wbm2sw_release_source_get(ring_desc, 326 HAL_BE_WBM_RELEASE_DIR_RX); 327 } 328 329 uint8_t hal_rx_ret_buf_manager_get_be(hal_ring_desc_t ring_desc) 330 { 331 /* 332 * The following macro takes buf_addr_info as argument, 333 * but since buf_addr_info is the first field in ring_desc 334 * Hence the following call is OK 335 */ 336 return HAL_RX_BUF_RBM_GET(ring_desc); 337 } 338 339 #define HAL_RX_WBM_REO_PUSH_REASON_GET(wbm_desc) (((*(((uint32_t *)wbm_desc) + \ 340 (WBM2SW_COMPLETION_RING_RX_REO_PUSH_REASON_OFFSET >> 2))) & \ 341 WBM2SW_COMPLETION_RING_RX_REO_PUSH_REASON_MASK) >> \ 342 WBM2SW_COMPLETION_RING_RX_REO_PUSH_REASON_LSB) 343 344 #define HAL_RX_WBM_REO_ERROR_CODE_GET(wbm_desc) (((*(((uint32_t *)wbm_desc) + \ 345 (WBM2SW_COMPLETION_RING_RX_REO_ERROR_CODE_OFFSET >> 2))) & \ 346 WBM2SW_COMPLETION_RING_RX_REO_ERROR_CODE_MASK) >> \ 347 WBM2SW_COMPLETION_RING_RX_REO_ERROR_CODE_LSB) 348 349 #define HAL_RX_WBM_RXDMA_PUSH_REASON_GET(wbm_desc) \ 350 (((*(((uint32_t *)wbm_desc) + \ 351 (WBM2SW_COMPLETION_RING_RX_RXDMA_PUSH_REASON_OFFSET >> 2))) & \ 352 WBM2SW_COMPLETION_RING_RX_RXDMA_PUSH_REASON_MASK) >> \ 353 WBM2SW_COMPLETION_RING_RX_RXDMA_PUSH_REASON_LSB) 354 355 #define HAL_RX_WBM_RXDMA_ERROR_CODE_GET(wbm_desc) \ 356 (((*(((uint32_t *)wbm_desc) + \ 357 (WBM2SW_COMPLETION_RING_RX_RXDMA_ERROR_CODE_OFFSET >> 2))) & \ 358 WBM2SW_COMPLETION_RING_RX_RXDMA_ERROR_CODE_MASK) >> \ 359 WBM2SW_COMPLETION_RING_RX_RXDMA_ERROR_CODE_LSB) 360 361 void hal_rx_wbm_err_info_get_generic_be(void *wbm_desc, void *wbm_er_info1) 362 { 363 struct hal_wbm_err_desc_info *wbm_er_info = 364 (struct hal_wbm_err_desc_info *)wbm_er_info1; 365 366 wbm_er_info->wbm_err_src = hal_rx_wbm_err_src_get_be(wbm_desc); 367 wbm_er_info->reo_psh_rsn = HAL_RX_WBM_REO_PUSH_REASON_GET(wbm_desc); 368 wbm_er_info->reo_err_code = HAL_RX_WBM_REO_ERROR_CODE_GET(wbm_desc); 369 wbm_er_info->rxdma_psh_rsn = HAL_RX_WBM_RXDMA_PUSH_REASON_GET(wbm_desc); 370 wbm_er_info->rxdma_err_code = HAL_RX_WBM_RXDMA_ERROR_CODE_GET(wbm_desc); 371 } 372 373 static void hal_rx_reo_buf_paddr_get_be(hal_ring_desc_t rx_desc, 374 struct hal_buf_info *buf_info) 375 { 376 struct reo_destination_ring *reo_ring = 377 (struct reo_destination_ring *)rx_desc; 378 379 buf_info->paddr = 380 (HAL_RX_REO_BUFFER_ADDR_31_0_GET(reo_ring) | 381 ((uint64_t)(HAL_RX_REO_BUFFER_ADDR_39_32_GET(reo_ring)) << 32)); 382 buf_info->sw_cookie = HAL_RX_REO_BUF_COOKIE_GET(reo_ring); 383 } 384 385 static void hal_rx_msdu_link_desc_set_be(hal_soc_handle_t hal_soc_hdl, 386 void *src_srng_desc, 387 hal_buff_addrinfo_t buf_addr_info, 388 uint8_t bm_action) 389 { 390 /* 391 * The offsets for fields used in this function are same in 392 * wbm_release_ring for Lithium and wbm_release_ring_tx 393 * for Beryllium. hence we can use wbm_release_ring directly. 394 */ 395 struct wbm_release_ring *wbm_rel_srng = 396 (struct wbm_release_ring *)src_srng_desc; 397 uint32_t addr_31_0; 398 uint8_t addr_39_32; 399 400 /* Structure copy !!! */ 401 wbm_rel_srng->released_buff_or_desc_addr_info = 402 *((struct buffer_addr_info *)buf_addr_info); 403 404 addr_31_0 = 405 wbm_rel_srng->released_buff_or_desc_addr_info.buffer_addr_31_0; 406 addr_39_32 = 407 wbm_rel_srng->released_buff_or_desc_addr_info.buffer_addr_39_32; 408 409 HAL_DESC_SET_FIELD(src_srng_desc, HAL_SW2WBM_RELEASE_RING, 410 RELEASE_SOURCE_MODULE, HAL_RX_WBM_ERR_SRC_SW); 411 HAL_DESC_SET_FIELD(src_srng_desc, HAL_SW2WBM_RELEASE_RING, BM_ACTION, 412 bm_action); 413 HAL_DESC_SET_FIELD(src_srng_desc, HAL_SW2WBM_RELEASE_RING, 414 BUFFER_OR_DESC_TYPE, 415 HAL_RX_WBM_BUF_TYPE_MSDU_LINK_DESC); 416 417 /* WBM error is indicated when any of the link descriptors given to 418 * WBM has a NULL address, and one those paths is the link descriptors 419 * released from host after processing RXDMA errors, 420 * or from Rx defrag path, and we want to add an assert here to ensure 421 * host is not releasing descriptors with NULL address. 422 */ 423 424 if (qdf_unlikely(!addr_31_0 && !addr_39_32)) { 425 hal_dump_wbm_rel_desc(src_srng_desc); 426 qdf_assert_always(0); 427 } 428 } 429 430 /** 431 * hal_rx_buf_cookie_rbm_get_be() - Get the cookie and return buffer 432 * manager from the REO entrance ring desc 433 * @buf_addr_info_hdl: Buffer address info element from ring desc 434 * @buf_info_hdl: structure to return the buffer information 435 * 436 * Return: void 437 */ 438 static 439 void hal_rx_buf_cookie_rbm_get_be(uint32_t *buf_addr_info_hdl, 440 hal_buf_info_t buf_info_hdl) 441 { 442 struct hal_buf_info *buf_info = 443 (struct hal_buf_info *)buf_info_hdl; 444 struct buffer_addr_info *buf_addr_info = 445 (struct buffer_addr_info *)buf_addr_info_hdl; 446 447 buf_info->sw_cookie = HAL_RX_BUF_COOKIE_GET(buf_addr_info); 448 /* 449 * buffer addr info is the first member of ring desc, so the typecast 450 * can be done. 451 */ 452 buf_info->rbm = hal_rx_ret_buf_manager_get_be( 453 (hal_ring_desc_t)buf_addr_info); 454 } 455 456 /** 457 * hal_rxdma_buff_addr_info_set_be() - set the buffer_addr_info of the 458 * rxdma ring entry. 459 * @rxdma_entry: descriptor entry 460 * @paddr: physical address of nbuf data pointer. 461 * @cookie: SW cookie used as a index to SW rx desc. 462 * @manager: who owns the nbuf (host, NSS, etc...). 463 * 464 */ 465 static inline void 466 hal_rxdma_buff_addr_info_set_be(void *rxdma_entry, 467 qdf_dma_addr_t paddr, uint32_t cookie, 468 uint8_t manager) 469 { 470 uint32_t paddr_lo = ((u64)paddr & 0x00000000ffffffff); 471 uint32_t paddr_hi = ((u64)paddr & 0xffffffff00000000) >> 32; 472 473 HAL_RXDMA_PADDR_LO_SET(rxdma_entry, paddr_lo); 474 HAL_RXDMA_PADDR_HI_SET(rxdma_entry, paddr_hi); 475 HAL_RXDMA_COOKIE_SET(rxdma_entry, cookie); 476 HAL_RXDMA_MANAGER_SET(rxdma_entry, manager); 477 } 478 479 /** 480 * hal_rx_get_reo_error_code_be() - Get REO error code from ring desc 481 * @rx_desc: rx descriptor 482 * 483 * Return: REO error code 484 */ 485 static uint32_t hal_rx_get_reo_error_code_be(hal_ring_desc_t rx_desc) 486 { 487 struct reo_destination_ring *reo_desc = 488 (struct reo_destination_ring *)rx_desc; 489 490 return HAL_RX_REO_ERROR_GET(reo_desc); 491 } 492 493 /** 494 * hal_gen_reo_remap_val_generic_be() - Generate the reo map value 495 * @remap_reg: remap register 496 * @ix0_map: mapping values for reo 497 * 498 * Return: IX0 reo remap register value to be written 499 */ 500 static uint32_t 501 hal_gen_reo_remap_val_generic_be(enum hal_reo_remap_reg remap_reg, 502 uint8_t *ix0_map) 503 { 504 uint32_t ix_val = 0; 505 506 switch (remap_reg) { 507 case HAL_REO_REMAP_REG_IX0: 508 ix_val = HAL_REO_REMAP_IX0(ix0_map[0], 0) | 509 HAL_REO_REMAP_IX0(ix0_map[1], 1) | 510 HAL_REO_REMAP_IX0(ix0_map[2], 2) | 511 HAL_REO_REMAP_IX0(ix0_map[3], 3) | 512 HAL_REO_REMAP_IX0(ix0_map[4], 4) | 513 HAL_REO_REMAP_IX0(ix0_map[5], 5) | 514 HAL_REO_REMAP_IX0(ix0_map[6], 6) | 515 HAL_REO_REMAP_IX0(ix0_map[7], 7); 516 break; 517 case HAL_REO_REMAP_REG_IX2: 518 ix_val = HAL_REO_REMAP_IX2(ix0_map[0], 16) | 519 HAL_REO_REMAP_IX2(ix0_map[1], 17) | 520 HAL_REO_REMAP_IX2(ix0_map[2], 18) | 521 HAL_REO_REMAP_IX2(ix0_map[3], 19) | 522 HAL_REO_REMAP_IX2(ix0_map[4], 20) | 523 HAL_REO_REMAP_IX2(ix0_map[5], 21) | 524 HAL_REO_REMAP_IX2(ix0_map[6], 22) | 525 HAL_REO_REMAP_IX2(ix0_map[7], 23); 526 break; 527 default: 528 break; 529 } 530 531 return ix_val; 532 } 533 534 static uint8_t hal_rx_err_status_get_be(hal_ring_desc_t rx_desc) 535 { 536 return HAL_RX_ERROR_STATUS_GET(rx_desc); 537 } 538 539 static QDF_STATUS hal_reo_status_update_be(hal_soc_handle_t hal_soc_hdl, 540 hal_ring_desc_t reo_desc, 541 void *st_handle, 542 uint32_t tlv, int *num_ref) 543 { 544 union hal_reo_status *reo_status_ref; 545 546 reo_status_ref = (union hal_reo_status *)st_handle; 547 548 switch (tlv) { 549 case HAL_REO_QUEUE_STATS_STATUS_TLV: 550 hal_reo_queue_stats_status_be(reo_desc, 551 &reo_status_ref->queue_status, 552 hal_soc_hdl); 553 *num_ref = reo_status_ref->queue_status.header.cmd_num; 554 break; 555 case HAL_REO_FLUSH_QUEUE_STATUS_TLV: 556 hal_reo_flush_queue_status_be(reo_desc, 557 &reo_status_ref->fl_queue_status, 558 hal_soc_hdl); 559 *num_ref = reo_status_ref->fl_queue_status.header.cmd_num; 560 break; 561 case HAL_REO_FLUSH_CACHE_STATUS_TLV: 562 hal_reo_flush_cache_status_be(reo_desc, 563 &reo_status_ref->fl_cache_status, 564 hal_soc_hdl); 565 *num_ref = reo_status_ref->fl_cache_status.header.cmd_num; 566 break; 567 case HAL_REO_UNBLK_CACHE_STATUS_TLV: 568 hal_reo_unblock_cache_status_be 569 (reo_desc, hal_soc_hdl, 570 &reo_status_ref->unblk_cache_status); 571 *num_ref = reo_status_ref->unblk_cache_status.header.cmd_num; 572 break; 573 case HAL_REO_TIMOUT_LIST_STATUS_TLV: 574 hal_reo_flush_timeout_list_status_be( 575 reo_desc, 576 &reo_status_ref->fl_timeout_status, 577 hal_soc_hdl); 578 *num_ref = reo_status_ref->fl_timeout_status.header.cmd_num; 579 break; 580 case HAL_REO_DESC_THRES_STATUS_TLV: 581 hal_reo_desc_thres_reached_status_be( 582 reo_desc, 583 &reo_status_ref->thres_status, 584 hal_soc_hdl); 585 *num_ref = reo_status_ref->thres_status.header.cmd_num; 586 break; 587 case HAL_REO_UPDATE_RX_QUEUE_STATUS_TLV: 588 hal_reo_rx_update_queue_status_be( 589 reo_desc, 590 &reo_status_ref->rx_queue_status, 591 hal_soc_hdl); 592 *num_ref = reo_status_ref->rx_queue_status.header.cmd_num; 593 break; 594 default: 595 QDF_TRACE(QDF_MODULE_ID_DP_REO, QDF_TRACE_LEVEL_WARN, 596 "hal_soc %pK: no handler for TLV:%d", 597 hal_soc_hdl, tlv); 598 return QDF_STATUS_E_FAILURE; 599 } /* switch */ 600 601 return QDF_STATUS_SUCCESS; 602 } 603 604 static uint8_t hal_rx_reo_buf_type_get_be(hal_ring_desc_t rx_desc) 605 { 606 return HAL_RX_REO_BUF_TYPE_GET(rx_desc); 607 } 608 609 #ifdef DP_HW_COOKIE_CONVERT_EXCEPTION 610 #define HAL_WBM_MISC_CONTROL_SPARE_CONTROL_FIELD_BIT15 0x8000 611 #endif 612 void hal_cookie_conversion_reg_cfg_be(hal_soc_handle_t hal_soc_hdl, 613 struct hal_hw_cc_config *cc_cfg) 614 { 615 struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl; 616 617 hal_soc->ops->hal_cookie_conversion_reg_cfg_be(hal_soc_hdl, cc_cfg); 618 } 619 qdf_export_symbol(hal_cookie_conversion_reg_cfg_be); 620 621 static inline void 622 hal_msdu_desc_info_set_be(hal_soc_handle_t hal_soc_hdl, 623 void *msdu_desc, uint32_t dst_ind, 624 uint32_t nbuf_len) 625 { 626 struct rx_msdu_desc_info *msdu_desc_info = 627 (struct rx_msdu_desc_info *)msdu_desc; 628 struct rx_msdu_ext_desc_info *msdu_ext_desc_info = 629 (struct rx_msdu_ext_desc_info *)(msdu_desc_info + 1); 630 631 HAL_RX_MSDU_DESC_INFO_SET(msdu_desc_info, 632 FIRST_MSDU_IN_MPDU_FLAG, 1); 633 HAL_RX_MSDU_DESC_INFO_SET(msdu_desc_info, 634 LAST_MSDU_IN_MPDU_FLAG, 1); 635 HAL_RX_MSDU_DESC_INFO_SET(msdu_desc_info, 636 MSDU_CONTINUATION, 0x0); 637 HAL_RX_MSDU_DESC_INFO_SET(msdu_desc_info, 638 MSDU_LENGTH, nbuf_len); 639 HAL_RX_MSDU_DESC_INFO_SET(msdu_desc_info, 640 SA_IS_VALID, 1); 641 HAL_RX_MSDU_DESC_INFO_SET(msdu_desc_info, 642 DA_IS_VALID, 1); 643 HAL_RX_MSDU_REO_DST_IND_SET(msdu_ext_desc_info, 644 REO_DESTINATION_INDICATION, dst_ind); 645 } 646 647 static inline void 648 hal_mpdu_desc_info_set_be(hal_soc_handle_t hal_soc_hdl, 649 void *ent_desc, 650 void *mpdu_desc, 651 uint32_t seq_no) 652 { 653 struct rx_mpdu_desc_info *mpdu_desc_info = 654 (struct rx_mpdu_desc_info *)mpdu_desc; 655 uint8_t *desc = (uint8_t *)ent_desc; 656 657 HAL_RX_FLD_SET(desc, REO_ENTRANCE_RING, 658 MPDU_SEQUENCE_NUMBER, seq_no); 659 660 HAL_RX_MPDU_DESC_INFO_SET(mpdu_desc_info, 661 MSDU_COUNT, 0x1); 662 HAL_RX_MPDU_DESC_INFO_SET(mpdu_desc_info, 663 FRAGMENT_FLAG, 0x1); 664 HAL_RX_MPDU_DESC_INFO_SET(mpdu_desc_info, 665 RAW_MPDU, 0x0); 666 } 667 668 /** 669 * hal_rx_msdu_reo_dst_ind_get_be() - Gets the REO destination ring ID 670 * from the msdu desc info 671 * @hal_soc_hdl: hal_soc handle 672 * @msdu_link_desc : Opaque cookie pointer used by HAL to get to 673 * the current descriptor 674 * 675 * Return: dst_ind (REO destination ring ID) 676 */ 677 static inline 678 uint32_t hal_rx_msdu_reo_dst_ind_get_be(hal_soc_handle_t hal_soc_hdl, 679 void *msdu_link_desc) 680 { 681 struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl; 682 struct rx_msdu_details *msdu_details; 683 struct rx_msdu_desc_info *msdu_desc_info; 684 struct rx_msdu_link *msdu_link = (struct rx_msdu_link *)msdu_link_desc; 685 uint32_t dst_ind; 686 687 msdu_details = hal_rx_link_desc_msdu0_ptr(msdu_link, hal_soc); 688 689 /* The first msdu in the link should exist */ 690 msdu_desc_info = hal_rx_msdu_ext_desc_info_get_ptr(&msdu_details[0], 691 hal_soc); 692 dst_ind = HAL_RX_MSDU_REO_DST_IND_GET(msdu_desc_info); 693 return dst_ind; 694 } 695 696 uint32_t 697 hal_reo_ix_remap_value_get_be(hal_soc_handle_t hal_soc_hdl, 698 uint8_t rx_ring_mask) 699 { 700 uint32_t num_rings = 0; 701 uint32_t i = 0; 702 uint32_t ring_remap_arr[HAL_MAX_REO2SW_RINGS] = {0}; 703 uint32_t reo_remap_val = 0; 704 uint32_t ring_idx = 0; 705 uint8_t ix_map[HAL_NUM_RX_RING_PER_IX_MAP] = {0}; 706 707 /* create reo ring remap array */ 708 while (i < HAL_MAX_REO2SW_RINGS) { 709 if (rx_ring_mask & (1 << i)) { 710 ring_remap_arr[num_rings] = reo_dest_ring_remap[i]; 711 num_rings++; 712 } 713 i++; 714 } 715 716 for (i = 0; i < HAL_NUM_RX_RING_PER_IX_MAP; i++) { 717 if (rx_ring_mask) { 718 ix_map[i] = ring_remap_arr[ring_idx]; 719 ring_idx = ((ring_idx + 1) % num_rings); 720 } else { 721 /* if ring mask is zero configure to release to WBM */ 722 ix_map[i] = REO_REMAP_RELEASE; 723 } 724 } 725 726 reo_remap_val = HAL_REO_REMAP_IX0(ix_map[0], 0) | 727 HAL_REO_REMAP_IX0(ix_map[1], 1) | 728 HAL_REO_REMAP_IX0(ix_map[2], 2) | 729 HAL_REO_REMAP_IX0(ix_map[3], 3) | 730 HAL_REO_REMAP_IX0(ix_map[4], 4) | 731 HAL_REO_REMAP_IX0(ix_map[5], 5) | 732 HAL_REO_REMAP_IX0(ix_map[6], 6) | 733 HAL_REO_REMAP_IX0(ix_map[7], 7); 734 735 return reo_remap_val; 736 } 737 738 qdf_export_symbol(hal_reo_ix_remap_value_get_be); 739 740 uint8_t hal_reo_ring_remap_value_get_be(uint8_t rx_ring_id) 741 { 742 if (rx_ring_id >= HAL_MAX_REO2SW_RINGS) 743 return REO_REMAP_RELEASE; 744 745 return reo_dest_ring_remap[rx_ring_id]; 746 } 747 748 qdf_export_symbol(hal_reo_ring_remap_value_get_be); 749 750 uint8_t hal_get_idle_link_bm_id_be(uint8_t chip_id) 751 { 752 if (chip_id >= HAL_NUM_CHIPS) 753 return HAL_WBM_CHIP_INVALID; 754 755 return wbm_idle_link_bm_map[chip_id]; 756 } 757 758 #ifdef DP_FEATURE_HW_COOKIE_CONVERSION 759 #ifdef DP_HW_COOKIE_CONVERT_EXCEPTION 760 static inline void 761 hal_rx_wbm_rel_buf_paddr_get_be(hal_ring_desc_t rx_desc, 762 struct hal_buf_info *buf_info) 763 { 764 if (hal_rx_wbm_get_cookie_convert_done(rx_desc)) 765 buf_info->paddr = 766 (HAL_RX_WBM_COMP_BUF_ADDR_31_0_GET(rx_desc) | 767 ((uint64_t)(HAL_RX_WBM_COMP_BUF_ADDR_39_32_GET(rx_desc)) << 32)); 768 else 769 buf_info->paddr = 770 (HAL_RX_WBM_BUF_ADDR_31_0_GET(rx_desc) | 771 ((uint64_t)(HAL_RX_WBM_BUF_ADDR_39_32_GET(rx_desc)) << 32)); 772 } 773 #else 774 static inline void 775 hal_rx_wbm_rel_buf_paddr_get_be(hal_ring_desc_t rx_desc, 776 struct hal_buf_info *buf_info) 777 { 778 buf_info->paddr = 779 (HAL_RX_WBM_COMP_BUF_ADDR_31_0_GET(rx_desc) | 780 ((uint64_t)(HAL_RX_WBM_COMP_BUF_ADDR_39_32_GET(rx_desc)) << 32)); 781 } 782 #endif 783 #else /* !DP_FEATURE_HW_COOKIE_CONVERSION */ 784 static inline void 785 hal_rx_wbm_rel_buf_paddr_get_be(hal_ring_desc_t rx_desc, 786 struct hal_buf_info *buf_info) 787 { 788 buf_info->paddr = 789 (HAL_RX_WBM_BUF_ADDR_31_0_GET(rx_desc) | 790 ((uint64_t)(HAL_RX_WBM_BUF_ADDR_39_32_GET(rx_desc)) << 32)); 791 } 792 #endif 793 794 #ifdef DP_UMAC_HW_RESET_SUPPORT 795 /** 796 * hal_unregister_reo_send_cmd_be() - Unregister Reo send command callback. 797 * @hal_soc: HAL soc handle 798 * 799 * Return: None 800 */ 801 static 802 void hal_unregister_reo_send_cmd_be(struct hal_soc *hal_soc) 803 { 804 hal_soc->ops->hal_reo_send_cmd = NULL; 805 } 806 807 /** 808 * hal_register_reo_send_cmd_be() - Register Reo send command callback. 809 * @hal_soc: HAL soc handle 810 * 811 * Return: None 812 */ 813 static 814 void hal_register_reo_send_cmd_be(struct hal_soc *hal_soc) 815 { 816 hal_soc->ops->hal_reo_send_cmd = hal_reo_send_cmd_be; 817 } 818 819 /** 820 * hal_reset_rx_reo_tid_q_be() - reset the reo tid queue. 821 * @hal_soc: HAL soc handle 822 * @hw_qdesc_vaddr: start address of the tid queue 823 * @size: size of address pointed by hw_qdesc_vaddr 824 * 825 * Return: None 826 */ 827 static void 828 hal_reset_rx_reo_tid_q_be(struct hal_soc *hal_soc, void *hw_qdesc_vaddr, 829 uint32_t size) 830 { 831 struct rx_reo_queue *hw_qdesc = (struct rx_reo_queue *)hw_qdesc_vaddr; 832 int i; 833 834 if (!hw_qdesc) 835 return; 836 837 hw_qdesc->svld = 0; 838 hw_qdesc->ssn = 0; 839 hw_qdesc->current_index = 0; 840 hw_qdesc->pn_valid = 0; 841 hw_qdesc->pn_31_0 = 0; 842 hw_qdesc->pn_63_32 = 0; 843 hw_qdesc->pn_95_64 = 0; 844 hw_qdesc->pn_127_96 = 0; 845 hw_qdesc->last_rx_enqueue_timestamp = 0; 846 hw_qdesc->last_rx_dequeue_timestamp = 0; 847 hw_qdesc->ptr_to_next_aging_queue_39_32 = 0; 848 hw_qdesc->ptr_to_next_aging_queue_31_0 = 0; 849 hw_qdesc->ptr_to_previous_aging_queue_31_0 = 0; 850 hw_qdesc->ptr_to_previous_aging_queue_39_32 = 0; 851 hw_qdesc->rx_bitmap_31_0 = 0; 852 hw_qdesc->rx_bitmap_63_32 = 0; 853 hw_qdesc->rx_bitmap_95_64 = 0; 854 hw_qdesc->rx_bitmap_127_96 = 0; 855 hw_qdesc->rx_bitmap_159_128 = 0; 856 hw_qdesc->rx_bitmap_191_160 = 0; 857 hw_qdesc->rx_bitmap_223_192 = 0; 858 hw_qdesc->rx_bitmap_255_224 = 0; 859 hw_qdesc->rx_bitmap_287_256 = 0; 860 hw_qdesc->current_msdu_count = 0; 861 hw_qdesc->current_mpdu_count = 0; 862 hw_qdesc->last_sn_reg_index = 0; 863 864 if (size > sizeof(struct rx_reo_queue)) { 865 struct rx_reo_queue_ext *ext_desc; 866 struct rx_reo_queue_1k *kdesc; 867 868 i = ((size - sizeof(struct rx_reo_queue)) / 869 sizeof(struct rx_reo_queue_ext)); 870 871 if (i > 10) { 872 i = 10; 873 kdesc = (struct rx_reo_queue_1k *) 874 (hw_qdesc_vaddr + sizeof(struct rx_reo_queue) + 875 (10 * sizeof(struct rx_reo_queue_ext))); 876 877 kdesc->rx_bitmap_319_288 = 0; 878 kdesc->rx_bitmap_351_320 = 0; 879 kdesc->rx_bitmap_383_352 = 0; 880 kdesc->rx_bitmap_415_384 = 0; 881 kdesc->rx_bitmap_447_416 = 0; 882 kdesc->rx_bitmap_479_448 = 0; 883 kdesc->rx_bitmap_511_480 = 0; 884 kdesc->rx_bitmap_543_512 = 0; 885 kdesc->rx_bitmap_575_544 = 0; 886 kdesc->rx_bitmap_607_576 = 0; 887 kdesc->rx_bitmap_639_608 = 0; 888 kdesc->rx_bitmap_671_640 = 0; 889 kdesc->rx_bitmap_703_672 = 0; 890 kdesc->rx_bitmap_735_704 = 0; 891 kdesc->rx_bitmap_767_736 = 0; 892 kdesc->rx_bitmap_799_768 = 0; 893 kdesc->rx_bitmap_831_800 = 0; 894 kdesc->rx_bitmap_863_832 = 0; 895 kdesc->rx_bitmap_895_864 = 0; 896 kdesc->rx_bitmap_927_896 = 0; 897 kdesc->rx_bitmap_959_928 = 0; 898 kdesc->rx_bitmap_991_960 = 0; 899 kdesc->rx_bitmap_1023_992 = 0; 900 } 901 902 ext_desc = (struct rx_reo_queue_ext *) 903 (hw_qdesc_vaddr + (sizeof(struct rx_reo_queue))); 904 905 while (i > 0) { 906 qdf_mem_zero(&ext_desc->mpdu_link_pointer_0, 907 (15 * sizeof(struct rx_mpdu_link_ptr))); 908 909 ext_desc++; 910 i--; 911 } 912 } 913 } 914 #endif 915 916 void hal_hw_txrx_default_ops_attach_be(struct hal_soc *hal_soc) 917 { 918 hal_soc->ops->hal_get_reo_qdesc_size = hal_get_reo_qdesc_size_be; 919 hal_soc->ops->hal_get_rx_max_ba_window = hal_get_rx_max_ba_window_be; 920 hal_soc->ops->hal_set_link_desc_addr = hal_set_link_desc_addr_be; 921 hal_soc->ops->hal_tx_init_data_ring = hal_tx_init_data_ring_be; 922 hal_soc->ops->hal_get_reo_reg_base_offset = 923 hal_get_reo_reg_base_offset_be; 924 hal_soc->ops->hal_reo_setup = hal_reo_setup_generic_be; 925 hal_soc->ops->hal_rx_reo_buf_paddr_get = hal_rx_reo_buf_paddr_get_be; 926 hal_soc->ops->hal_rx_msdu_link_desc_set = hal_rx_msdu_link_desc_set_be; 927 hal_soc->ops->hal_rx_buf_cookie_rbm_get = hal_rx_buf_cookie_rbm_get_be; 928 929 hal_soc->ops->hal_rx_ret_buf_manager_get = 930 hal_rx_ret_buf_manager_get_be; 931 hal_soc->ops->hal_rxdma_buff_addr_info_set = 932 hal_rxdma_buff_addr_info_set_be; 933 hal_soc->ops->hal_rx_msdu_flags_get = hal_rx_msdu_flags_get_be; 934 hal_soc->ops->hal_rx_get_reo_error_code = hal_rx_get_reo_error_code_be; 935 hal_soc->ops->hal_gen_reo_remap_val = 936 hal_gen_reo_remap_val_generic_be; 937 hal_soc->ops->hal_tx_comp_get_buffer_source = 938 hal_tx_comp_get_buffer_source_generic_be; 939 hal_soc->ops->hal_tx_comp_get_release_reason = 940 hal_tx_comp_get_release_reason_generic_be; 941 hal_soc->ops->hal_get_wbm_internal_error = 942 hal_get_wbm_internal_error_generic_be; 943 hal_soc->ops->hal_rx_mpdu_desc_info_get = 944 hal_rx_mpdu_desc_info_get_be; 945 hal_soc->ops->hal_rx_err_status_get = hal_rx_err_status_get_be; 946 hal_soc->ops->hal_rx_reo_buf_type_get = hal_rx_reo_buf_type_get_be; 947 hal_soc->ops->hal_rx_wbm_err_src_get = hal_rx_wbm_err_src_get_be; 948 hal_soc->ops->hal_rx_wbm_rel_buf_paddr_get = 949 hal_rx_wbm_rel_buf_paddr_get_be; 950 951 hal_soc->ops->hal_reo_send_cmd = hal_reo_send_cmd_be; 952 hal_soc->ops->hal_reo_qdesc_setup = hal_reo_qdesc_setup_be; 953 hal_soc->ops->hal_reo_status_update = hal_reo_status_update_be; 954 hal_soc->ops->hal_get_tlv_hdr_size = hal_get_tlv_hdr_size_be; 955 hal_soc->ops->hal_rx_msdu_reo_dst_ind_get = 956 hal_rx_msdu_reo_dst_ind_get_be; 957 hal_soc->ops->hal_get_idle_link_bm_id = hal_get_idle_link_bm_id_be; 958 hal_soc->ops->hal_rx_msdu_ext_desc_info_get_ptr = 959 hal_rx_msdu_ext_desc_info_get_ptr_be; 960 hal_soc->ops->hal_msdu_desc_info_set = hal_msdu_desc_info_set_be; 961 hal_soc->ops->hal_mpdu_desc_info_set = hal_mpdu_desc_info_set_be; 962 #ifdef DP_UMAC_HW_RESET_SUPPORT 963 hal_soc->ops->hal_unregister_reo_send_cmd = 964 hal_unregister_reo_send_cmd_be; 965 hal_soc->ops->hal_register_reo_send_cmd = hal_register_reo_send_cmd_be; 966 hal_soc->ops->hal_reset_rx_reo_tid_q = hal_reset_rx_reo_tid_q_be; 967 #endif 968 hal_soc->ops->hal_rx_tlv_get_pn_num = hal_rx_tlv_get_pn_num_be; 969 #ifndef CONFIG_WORD_BASED_TLV 970 hal_soc->ops->hal_rx_get_qdesc_addr = hal_rx_get_qdesc_addr_be; 971 #endif 972 hal_soc->ops->hal_set_reo_ent_desc_reo_dest_ind = 973 hal_set_reo_ent_desc_reo_dest_ind_be; 974 hal_soc->ops->hal_get_reo_ent_desc_qdesc_addr = 975 hal_get_reo_ent_desc_qdesc_addr_be; 976 } 977