1 /* 2 * Copyright (c) 2016-2020 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef _DP_HTT_H_ 20 #define _DP_HTT_H_ 21 22 #include <qdf_types.h> 23 #include <qdf_lock.h> 24 #include <qdf_nbuf.h> 25 #include <htc_api.h> 26 27 #include "cdp_txrx_cmn_struct.h" 28 #include "dp_types.h" 29 #ifdef HTT_LOGGER 30 #include "dp_htt_logger.h" 31 #else 32 struct htt_logger; 33 static inline 34 void htt_interface_logging_init(struct htt_logger **htt_logger_handle) 35 { 36 } 37 38 static inline 39 void htt_interface_logging_deinit(struct htt_logger *htt_logger_handle) 40 { 41 } 42 43 static inline 44 int htt_command_record(struct htt_logger *h, uint8_t msg_type, 45 uint8_t *msg_data) 46 { 47 return 0; 48 } 49 50 static inline 51 int htt_event_record(struct htt_logger *h, uint8_t msg_type, 52 uint8_t *msg_data) 53 { 54 return 0; 55 } 56 57 static inline 58 int htt_wbm_event_record(struct htt_logger *h, uint8_t tx_status, 59 uint8_t *msg_data) 60 { 61 return 0; 62 } 63 64 #endif 65 66 #define HTT_TX_MUTEX_TYPE qdf_spinlock_t 67 68 #define HTT_TX_MUTEX_INIT(_mutex) \ 69 qdf_spinlock_create(_mutex) 70 71 #define HTT_TX_MUTEX_ACQUIRE(_mutex) \ 72 qdf_spin_lock_bh(_mutex) 73 74 #define HTT_TX_MUTEX_RELEASE(_mutex) \ 75 qdf_spin_unlock_bh(_mutex) 76 77 #define HTT_TX_MUTEX_DESTROY(_mutex) \ 78 qdf_spinlock_destroy(_mutex) 79 80 #define DP_HTT_MAX_SEND_QUEUE_DEPTH 64 81 82 #ifndef HTT_MAC_ADDR_LEN 83 #define HTT_MAC_ADDR_LEN 6 84 #endif 85 86 #define HTT_FRAMECTRL_TYPE_MASK 0x0C 87 #define HTT_GET_FRAME_CTRL_TYPE(_val) \ 88 (((_val) & HTT_FRAMECTRL_TYPE_MASK) >> 2) 89 #define FRAME_CTRL_TYPE_MGMT 0x0 90 #define FRAME_CTRL_TYPE_CTRL 0x1 91 #define FRAME_CTRL_TYPE_DATA 0x2 92 #define FRAME_CTRL_TYPE_RESV 0x3 93 94 #define HTT_FRAMECTRL_DATATYPE 0x08 95 #define HTT_PPDU_DESC_MAX_DEPTH 16 96 #define DP_SCAN_PEER_ID 0xFFFF 97 98 #define DP_HTT_HTC_PKT_MISCLIST_SIZE 256 99 #define HTT_T2H_MAX_MSG_SIZE 2048 100 101 #define HTT_T2H_EXT_STATS_TLV_START_OFFSET 3 102 103 /* 104 * Below offset are based on htt_ppdu_stats_common_tlv 105 * defined in htt_ppdu_stats.h 106 */ 107 #define HTT_PPDU_STATS_COMMON_TLV_TLV_HDR_OFFSET 0 108 #define HTT_PPDU_STATS_COMMON_TLV_PPDU_ID_OFFSET 1 109 #define HTT_PPDU_STATS_COMMON_TLV_RING_ID_SCH_CMD_ID_OFFSET 2 110 #define HTT_PPDU_STATS_COMMON_TLV_QTYPE_FRM_TYPE_OFFSET 3 111 #define HTT_PPDU_STATS_COMMON_TLV_CHAIN_MASK_OFFSET 4 112 #define HTT_PPDU_STATS_COMMON_TLV_FES_DUR_US_OFFSET 5 113 #define HTT_PPDU_STATS_COMMON_TLV_SCH_EVAL_START_TSTMP_L32_US_OFFSET 6 114 #define HTT_PPDU_STATS_COMMON_TLV_SCH_END_TSTMP_US_OFFSET 7 115 #define HTT_PPDU_STATS_COMMON_TLV_START_TSTMP_L32_US_OFFSET 8 116 #define HTT_PPDU_STATS_COMMON_TLV_CHAN_MHZ_PHY_MODE_OFFSET 9 117 #define HTT_PPDU_STATS_COMMON_TLV_CCA_DELTA_TIME_US_OFFSET 10 118 #define HTT_PPDU_STATS_COMMON_TLV_RXFRM_DELTA_TIME_US_OFFSET 11 119 #define HTT_PPDU_STATS_COMMON_TLV_TXFRM_DELTA_TIME_US_OFFSET 12 120 #define HTT_PPDU_STATS_COMMON_TLV_RESV_NUM_UL_BEAM_OFFSET 13 121 #define HTT_PPDU_STATS_COMMON_TLV_START_TSTMP_U32_US_OFFSET 14 122 123 /* get index for field in htt_ppdu_stats_common_tlv */ 124 #define HTT_GET_STATS_CMN_INDEX(index) \ 125 HTT_PPDU_STATS_COMMON_TLV_##index##_OFFSET 126 127 struct dp_htt_htc_pkt { 128 void *soc_ctxt; 129 qdf_dma_addr_t nbuf_paddr; 130 HTC_PACKET htc_pkt; 131 }; 132 133 struct dp_htt_htc_pkt_union { 134 union { 135 struct dp_htt_htc_pkt pkt; 136 struct dp_htt_htc_pkt_union *next; 137 } u; 138 }; 139 140 struct dp_htt_timestamp { 141 long *umac_ttt; 142 long *lmac_ttt; 143 }; 144 145 struct htt_soc { 146 struct cdp_ctrl_objmgr_psoc *ctrl_psoc; 147 struct dp_soc *dp_soc; 148 hal_soc_handle_t hal_soc; 149 struct dp_htt_timestamp pdevid_tt[MAX_PDEV_CNT]; 150 /* htt_logger handle */ 151 struct htt_logger *htt_logger_handle; 152 HTC_HANDLE htc_soc; 153 qdf_device_t osdev; 154 HTC_ENDPOINT_ID htc_endpoint; 155 struct dp_htt_htc_pkt_union *htt_htc_pkt_freelist; 156 struct dp_htt_htc_pkt_union *htt_htc_pkt_misclist; 157 struct { 158 u_int8_t major; 159 u_int8_t minor; 160 } tgt_ver; 161 struct { 162 u_int8_t major; 163 u_int8_t minor; 164 } wifi_ip_ver; 165 166 struct { 167 int htc_err_cnt; 168 int htc_pkt_free; 169 } stats; 170 171 HTT_TX_MUTEX_TYPE htt_tx_mutex; 172 }; 173 174 /** 175 * struct htt_rx_ring_tlv_filter - Rx ring TLV filter 176 * enable/disable. 177 * @mpdu_start: enable/disable MPDU start TLV 178 * @msdu_start: enable/disable MSDU start TLV 179 * @packet: enable/disable PACKET TLV 180 * @msdu_end: enable/disable MSDU end TLV 181 * @mpdu_end: enable/disable MPDU end TLV 182 * @packet_header: enable/disable PACKET header TLV 183 * @attention: enable/disable ATTENTION TLV 184 * @ppdu_start: enable/disable PPDU start TLV 185 * @ppdu_end: enable/disable PPDU end TLV 186 * @ppdu_end_user_stats: enable/disable PPDU user stats TLV 187 * @ppdu_end_user_stats_ext: enable/disable PPDU user stats ext TLV 188 * @ppdu_end_status_done: enable/disable PPDU end status done TLV 189 * @enable_fp: enable/disable FP packet 190 * @enable_md: enable/disable MD packet 191 * @enable_mo: enable/disable MO packet 192 * @enable_mgmt: enable/disable MGMT packet 193 * @enable_ctrl: enable/disable CTRL packet 194 * @enable_data: enable/disable DATA packet 195 * @offset_valid: Flag to indicate if below offsets are valid 196 * @rx_packet_offset: Offset of packet payload 197 * @rx_header_offset: Offset of rx_header tlv 198 * @rx_mpdu_end_offset: Offset of rx_mpdu_end tlv 199 * @rx_mpdu_start_offset: Offset of rx_mpdu_start tlv 200 * @rx_msdu_end_offset: Offset of rx_msdu_end tlv 201 * @rx_msdu_start_offset: Offset of rx_msdu_start tlv 202 * @rx_attn_offset: Offset of rx_attention tlv 203 * 204 * NOTE: Do not change the layout of this structure 205 */ 206 struct htt_rx_ring_tlv_filter { 207 u_int32_t mpdu_start:1, 208 msdu_start:1, 209 packet:1, 210 msdu_end:1, 211 mpdu_end:1, 212 packet_header:1, 213 attention:1, 214 ppdu_start:1, 215 ppdu_end:1, 216 ppdu_end_user_stats:1, 217 ppdu_end_user_stats_ext:1, 218 ppdu_end_status_done:1, 219 header_per_msdu:1, 220 enable_fp:1, 221 enable_md:1, 222 enable_mo:1; 223 u_int32_t fp_mgmt_filter:16, 224 mo_mgmt_filter:16; 225 u_int32_t fp_ctrl_filter:16, 226 mo_ctrl_filter:16; 227 u_int32_t fp_data_filter:16, 228 mo_data_filter:16; 229 u_int16_t md_data_filter; 230 u_int16_t md_mgmt_filter; 231 u_int16_t md_ctrl_filter; 232 bool offset_valid; 233 uint16_t rx_packet_offset; 234 uint16_t rx_header_offset; 235 uint16_t rx_mpdu_end_offset; 236 uint16_t rx_mpdu_start_offset; 237 uint16_t rx_msdu_end_offset; 238 uint16_t rx_msdu_start_offset; 239 uint16_t rx_attn_offset; 240 }; 241 242 /** 243 * struct dp_htt_rx_flow_fst_setup - Rx FST setup message 244 * @pdev_id: DP Pdev identifier 245 * @max_entries: Size of Rx FST in number of entries 246 * @max_search: Number of collisions allowed 247 * @base_addr_lo: lower 32-bit physical address 248 * @base_addr_hi: upper 32-bit physical address 249 * @ip_da_sa_prefix: IPv4 prefix to map to IPv6 address scheme 250 * @hash_key_len: Rx FST hash key size 251 * @hash_key: Rx FST Toeplitz hash key 252 */ 253 struct dp_htt_rx_flow_fst_setup { 254 uint8_t pdev_id; 255 uint32_t max_entries; 256 uint32_t max_search; 257 uint32_t base_addr_lo; 258 uint32_t base_addr_hi; 259 uint32_t ip_da_sa_prefix; 260 uint32_t hash_key_len; 261 uint8_t *hash_key; 262 }; 263 264 /** 265 * enum dp_htt_flow_fst_operation - FST related operations allowed 266 * @DP_HTT_FST_CACHE_OP_NONE: Cache no-op 267 * @DP_HTT_FST_CACHE_INVALIDATE_ENTRY: Invalidate single cache entry 268 * @DP_HTT_FST_CACHE_INVALIDATE_FULL: Invalidate entire cache 269 * @DP_HTT_FST_ENABLE: Bypass FST is enabled 270 * @DP_HTT_FST_DISABLE: Disable bypass FST 271 */ 272 enum dp_htt_flow_fst_operation { 273 DP_HTT_FST_CACHE_OP_NONE, 274 DP_HTT_FST_CACHE_INVALIDATE_ENTRY, 275 DP_HTT_FST_CACHE_INVALIDATE_FULL, 276 DP_HTT_FST_ENABLE, 277 DP_HTT_FST_DISABLE 278 }; 279 280 /** 281 * struct dp_htt_rx_flow_fst_setup - Rx FST setup message 282 * @pdev_id: DP Pdev identifier 283 * @op_code: FST operation to be performed by FW/HW 284 * @rx_flow: Rx Flow information on which operation is to be performed 285 */ 286 struct dp_htt_rx_flow_fst_operation { 287 uint8_t pdev_id; 288 enum dp_htt_flow_fst_operation op_code; 289 struct cdp_rx_flow_info *rx_flow; 290 }; 291 292 /* 293 * htt_soc_initialize() - SOC level HTT initialization 294 * @htt_soc: Opaque htt SOC handle 295 * @ctrl_psoc: Opaque ctrl SOC handle 296 * @htc_soc: SOC level HTC handle 297 * @hal_soc: Opaque HAL SOC handle 298 * @osdev: QDF device 299 * 300 * Return: HTT handle on success; NULL on failure 301 */ 302 void * 303 htt_soc_initialize(struct htt_soc *htt_soc, 304 struct cdp_ctrl_objmgr_psoc *ctrl_psoc, 305 HTC_HANDLE htc_soc, 306 hal_soc_handle_t hal_soc_hdl, qdf_device_t osdev); 307 308 /* 309 * htt_soc_attach() - attach DP and HTT SOC 310 * @soc: DP SOC handle 311 * @htc_hdl: HTC handle 312 * 313 * Return: htt_soc handle on Success, NULL on Failure 314 */ 315 struct htt_soc *htt_soc_attach(struct dp_soc *soc, HTC_HANDLE htc_hdl); 316 317 /* 318 * htt_set_htc_handle_() - set HTC handle 319 * @htt_hdl: HTT handle/SOC 320 * @htc_soc: HTC handle 321 * 322 * Return: None 323 */ 324 void htt_set_htc_handle(struct htt_soc *htt_hdl, HTC_HANDLE htc_soc); 325 326 /* 327 * htt_get_htc_handle_() - set HTC handle 328 * @htt_hdl: HTT handle/SOC 329 * 330 * Return: HTC_HANDLE 331 */ 332 HTC_HANDLE htt_get_htc_handle(struct htt_soc *htt_hdl); 333 334 /* 335 * htt_soc_htc_dealloc() - HTC memory de-alloc 336 * @htt_soc: SOC level HTT handle 337 * 338 * Return: None 339 */ 340 void htt_soc_htc_dealloc(struct htt_soc *htt_handle); 341 342 /* 343 * htt_soc_htc_prealloc() - HTC memory prealloc 344 * @htt_soc: SOC level HTT handle 345 * 346 * Return: QDF_STATUS_SUCCESS on success or 347 * QDF_STATUS_E_NO_MEM on allocation failure 348 */ 349 QDF_STATUS htt_soc_htc_prealloc(struct htt_soc *htt_soc); 350 351 void htt_soc_detach(struct htt_soc *soc); 352 353 int htt_srng_setup(struct htt_soc *htt_soc, int pdev_id, 354 hal_ring_handle_t hal_ring_hdl, 355 int hal_ring_type); 356 357 int htt_soc_attach_target(struct htt_soc *htt_soc); 358 359 /* 360 * htt_h2t_rx_ring_cfg() - Send SRNG packet and TLV filter 361 * config message to target 362 * @htt_soc: HTT SOC handle 363 * @pdev_id: PDEV Id 364 * @hal_srng: Opaque HAL SRNG pointer 365 * @hal_ring_type: SRNG ring type 366 * @ring_buf_size: SRNG buffer size 367 * @htt_tlv_filter: Rx SRNG TLV and filter setting 368 * 369 * Return: 0 on success; error code on failure 370 */ 371 int htt_h2t_rx_ring_cfg(struct htt_soc *htt_soc, int pdev_id, 372 hal_ring_handle_t hal_ring_hdl, 373 int hal_ring_type, int ring_buf_size, 374 struct htt_rx_ring_tlv_filter *htt_tlv_filter); 375 376 /* 377 * htt_t2h_stats_handler() - target to host stats work handler 378 * @context: context (dp soc context) 379 * 380 * Return: void 381 */ 382 void htt_t2h_stats_handler(void *context); 383 384 /** 385 * struct htt_stats_context - htt stats information 386 * @soc: Size of each descriptor in the pool 387 * @msg: T2H Ext stats message queue 388 * @msg_len: T2H Ext stats message length 389 */ 390 struct htt_stats_context { 391 struct dp_soc *soc; 392 qdf_nbuf_queue_t msg; 393 uint32_t msg_len; 394 }; 395 396 int 397 dp_htt_get_ppdu_sniffer_ampdu_tlv_bitmap(uint32_t bitmap); 398 399 /** 400 * dp_ppdu_desc_user_stats_update(): Function to update TX user stats 401 * @pdev: DP pdev handle 402 * @ppdu_info: per PPDU TLV descriptor 403 * 404 * return: void 405 */ 406 void 407 dp_ppdu_desc_user_stats_update(struct dp_pdev *pdev, 408 struct ppdu_info *ppdu_info); 409 410 /** 411 * dp_htt_rx_flow_fst_setup(): Send HTT Rx FST setup message to FW 412 * @pdev: DP pdev handle 413 * @fse_setup_info: FST setup parameters 414 * 415 * Return: Success when HTT message is sent, error on failure 416 */ 417 QDF_STATUS 418 dp_htt_rx_flow_fst_setup(struct dp_pdev *pdev, 419 struct dp_htt_rx_flow_fst_setup *setup_info); 420 421 /** 422 * dp_htt_rx_flow_fse_operation(): Send HTT Flow Search Entry msg to 423 * add/del a flow in HW 424 * @pdev: DP pdev handle 425 * @fse_op_info: Flow entry parameters 426 * 427 * Return: Success when HTT message is sent, error on failure 428 */ 429 QDF_STATUS 430 dp_htt_rx_flow_fse_operation(struct dp_pdev *pdev, 431 struct dp_htt_rx_flow_fst_operation *op_info); 432 #endif /* _DP_HTT_H_ */ 433