1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ 2 /* 3 * Copyright (C) 2005-2014, 2018-2025 Intel Corporation 4 * Copyright (C) 2013-2015 Intel Mobile Communications GmbH 5 * Copyright (C) 2016-2017 Intel Deutschland GmbH 6 */ 7 #ifndef __iwl_trans_h__ 8 #define __iwl_trans_h__ 9 10 #include <linux/ieee80211.h> 11 #include <linux/mm.h> /* for page_address */ 12 #include <linux/lockdep.h> 13 #include <linux/kernel.h> 14 15 #include "iwl-debug.h" 16 #include "iwl-config.h" 17 #include "fw/img.h" 18 #include "iwl-op-mode.h" 19 #include <linux/firmware.h> 20 #include "fw/api/cmdhdr.h" 21 #include "fw/api/txq.h" 22 #include "fw/api/dbg-tlv.h" 23 #include "iwl-dbg-tlv.h" 24 25 /** 26 * DOC: Transport layer - what is it ? 27 * 28 * The transport layer is the layer that deals with the HW directly. It provides 29 * the PCIe access to the underlying hardwarwe. The transport layer doesn't 30 * provide any policy, algorithm or anything of this kind, but only mechanisms 31 * to make the HW do something. It is not completely stateless but close to it. 32 */ 33 34 /** 35 * DOC: Life cycle of the transport layer 36 * 37 * The transport layer has a very precise life cycle. 38 * 39 * 1) A helper function is called during the module initialization and 40 * registers the bus driver's ops with the transport's alloc function. 41 * 2) Bus's probe calls to the transport layer's allocation functions. 42 * Of course this function is bus specific. 43 * 3) This allocation functions will spawn the upper layer which will 44 * register mac80211. 45 * 46 * 4) At some point (i.e. mac80211's start call), the op_mode will call 47 * the following sequence: 48 * start_hw 49 * start_fw 50 * 51 * 5) Then when finished (or reset): 52 * stop_device 53 * 54 * 6) Eventually, the free function will be called. 55 */ 56 57 /* default preset 0 (start from bit 16)*/ 58 #define IWL_FW_DBG_DOMAIN_POS 16 59 #define IWL_FW_DBG_DOMAIN BIT(IWL_FW_DBG_DOMAIN_POS) 60 61 #define IWL_TRANS_FW_DBG_DOMAIN(trans) IWL_FW_INI_DOMAIN_ALWAYS_ON 62 63 #define FH_RSCSR_FRAME_SIZE_MSK 0x00003FFF /* bits 0-13 */ 64 #define FH_RSCSR_FRAME_INVALID 0x55550000 65 #define FH_RSCSR_FRAME_ALIGN 0x40 66 #define FH_RSCSR_RPA_EN BIT(25) 67 #define FH_RSCSR_RADA_EN BIT(26) 68 #define FH_RSCSR_RXQ_POS 16 69 #define FH_RSCSR_RXQ_MASK 0x3F0000 70 71 struct iwl_rx_packet { 72 /* 73 * The first 4 bytes of the RX frame header contain both the RX frame 74 * size and some flags. 75 * Bit fields: 76 * 31: flag flush RB request 77 * 30: flag ignore TC (terminal counter) request 78 * 29: flag fast IRQ request 79 * 28-27: Reserved 80 * 26: RADA enabled 81 * 25: Offload enabled 82 * 24: RPF enabled 83 * 23: RSS enabled 84 * 22: Checksum enabled 85 * 21-16: RX queue 86 * 15-14: Reserved 87 * 13-00: RX frame size 88 */ 89 __le32 len_n_flags; 90 struct iwl_cmd_header hdr; 91 u8 data[]; 92 } __packed; 93 94 static inline u32 iwl_rx_packet_len(const struct iwl_rx_packet *pkt) 95 { 96 return le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; 97 } 98 99 static inline u32 iwl_rx_packet_payload_len(const struct iwl_rx_packet *pkt) 100 { 101 return iwl_rx_packet_len(pkt) - sizeof(pkt->hdr); 102 } 103 104 /** 105 * enum CMD_MODE - how to send the host commands ? 106 * 107 * @CMD_ASYNC: Return right away and don't wait for the response 108 * @CMD_WANT_SKB: Not valid with CMD_ASYNC. The caller needs the buffer of 109 * the response. The caller needs to call iwl_free_resp when done. 110 * @CMD_SEND_IN_RFKILL: Send the command even if the NIC is in RF-kill. 111 * @CMD_BLOCK_TXQS: Block TXQs while the comment is executing. 112 */ 113 enum CMD_MODE { 114 CMD_ASYNC = BIT(0), 115 CMD_WANT_SKB = BIT(1), 116 CMD_SEND_IN_RFKILL = BIT(2), 117 CMD_BLOCK_TXQS = BIT(3), 118 }; 119 #define CMD_MODE_BITS 5 120 121 #define DEF_CMD_PAYLOAD_SIZE 320 122 123 /** 124 * struct iwl_device_cmd 125 * 126 * For allocation of the command and tx queues, this establishes the overall 127 * size of the largest command we send to uCode, except for commands that 128 * aren't fully copied and use other TFD space. 129 * 130 * @hdr: command header 131 * @payload: payload for the command 132 * @hdr_wide: wide command header 133 * @payload_wide: payload for the wide command 134 */ 135 struct iwl_device_cmd { 136 union { 137 struct { 138 struct iwl_cmd_header hdr; /* uCode API */ 139 u8 payload[DEF_CMD_PAYLOAD_SIZE]; 140 }; 141 struct { 142 struct iwl_cmd_header_wide hdr_wide; 143 u8 payload_wide[DEF_CMD_PAYLOAD_SIZE - 144 sizeof(struct iwl_cmd_header_wide) + 145 sizeof(struct iwl_cmd_header)]; 146 }; 147 }; 148 } __packed; 149 150 /** 151 * struct iwl_device_tx_cmd - buffer for TX command 152 * @hdr: the header 153 * @payload: the payload placeholder 154 * 155 * The actual structure is sized dynamically according to need. 156 */ 157 struct iwl_device_tx_cmd { 158 struct iwl_cmd_header hdr; 159 u8 payload[]; 160 } __packed; 161 162 #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_device_cmd)) 163 164 /* 165 * number of transfer buffers (fragments) per transmit frame descriptor; 166 * this is just the driver's idea, the hardware supports 20 167 */ 168 #define IWL_MAX_CMD_TBS_PER_TFD 2 169 170 /** 171 * enum iwl_hcmd_dataflag - flag for each one of the chunks of the command 172 * 173 * @IWL_HCMD_DFL_NOCOPY: By default, the command is copied to the host command's 174 * ring. The transport layer doesn't map the command's buffer to DMA, but 175 * rather copies it to a previously allocated DMA buffer. This flag tells 176 * the transport layer not to copy the command, but to map the existing 177 * buffer (that is passed in) instead. This saves the memcpy and allows 178 * commands that are bigger than the fixed buffer to be submitted. 179 * Note that a TFD entry after a NOCOPY one cannot be a normal copied one. 180 * @IWL_HCMD_DFL_DUP: Only valid without NOCOPY, duplicate the memory for this 181 * chunk internally and free it again after the command completes. This 182 * can (currently) be used only once per command. 183 * Note that a TFD entry after a DUP one cannot be a normal copied one. 184 */ 185 enum iwl_hcmd_dataflag { 186 IWL_HCMD_DFL_NOCOPY = BIT(0), 187 IWL_HCMD_DFL_DUP = BIT(1), 188 }; 189 190 enum iwl_error_event_table_status { 191 IWL_ERROR_EVENT_TABLE_LMAC1 = BIT(0), 192 IWL_ERROR_EVENT_TABLE_LMAC2 = BIT(1), 193 IWL_ERROR_EVENT_TABLE_UMAC = BIT(2), 194 IWL_ERROR_EVENT_TABLE_TCM1 = BIT(3), 195 IWL_ERROR_EVENT_TABLE_TCM2 = BIT(4), 196 IWL_ERROR_EVENT_TABLE_RCM1 = BIT(5), 197 IWL_ERROR_EVENT_TABLE_RCM2 = BIT(6), 198 }; 199 200 /** 201 * struct iwl_host_cmd - Host command to the uCode 202 * 203 * @data: array of chunks that composes the data of the host command 204 * @resp_pkt: response packet, if %CMD_WANT_SKB was set 205 * @_rx_page_order: (internally used to free response packet) 206 * @_rx_page_addr: (internally used to free response packet) 207 * @flags: can be CMD_* 208 * @len: array of the lengths of the chunks in data 209 * @dataflags: IWL_HCMD_DFL_* 210 * @id: command id of the host command, for wide commands encoding the 211 * version and group as well 212 */ 213 struct iwl_host_cmd { 214 const void *data[IWL_MAX_CMD_TBS_PER_TFD]; 215 struct iwl_rx_packet *resp_pkt; 216 unsigned long _rx_page_addr; 217 u32 _rx_page_order; 218 219 u32 flags; 220 u32 id; 221 u16 len[IWL_MAX_CMD_TBS_PER_TFD]; 222 u8 dataflags[IWL_MAX_CMD_TBS_PER_TFD]; 223 }; 224 225 static inline void iwl_free_resp(struct iwl_host_cmd *cmd) 226 { 227 free_pages(cmd->_rx_page_addr, cmd->_rx_page_order); 228 } 229 230 struct iwl_rx_cmd_buffer { 231 struct page *_page; 232 int _offset; 233 bool _page_stolen; 234 u32 _rx_page_order; 235 unsigned int truesize; 236 }; 237 238 static inline void *rxb_addr(struct iwl_rx_cmd_buffer *r) 239 { 240 return (void *)((unsigned long)page_address(r->_page) + r->_offset); 241 } 242 243 static inline int rxb_offset(struct iwl_rx_cmd_buffer *r) 244 { 245 return r->_offset; 246 } 247 248 static inline struct page *rxb_steal_page(struct iwl_rx_cmd_buffer *r) 249 { 250 r->_page_stolen = true; 251 get_page(r->_page); 252 return r->_page; 253 } 254 255 static inline void iwl_free_rxb(struct iwl_rx_cmd_buffer *r) 256 { 257 __free_pages(r->_page, r->_rx_page_order); 258 } 259 260 #define MAX_NO_RECLAIM_CMDS 6 261 262 #define IWL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo)))) 263 264 /* 265 * Maximum number of HW queues the transport layer 266 * currently supports 267 */ 268 #define IWL_MAX_HW_QUEUES 32 269 #define IWL_MAX_TVQM_QUEUES 512 270 271 #define IWL_MAX_TID_COUNT 8 272 #define IWL_MGMT_TID 15 273 #define IWL_FRAME_LIMIT 64 274 #define IWL_MAX_RX_HW_QUEUES 16 275 #define IWL_9000_MAX_RX_HW_QUEUES 1 276 277 /** 278 * enum iwl_d3_status - WoWLAN image/device status 279 * @IWL_D3_STATUS_ALIVE: firmware is still running after resume 280 * @IWL_D3_STATUS_RESET: device was reset while suspended 281 */ 282 enum iwl_d3_status { 283 IWL_D3_STATUS_ALIVE, 284 IWL_D3_STATUS_RESET, 285 }; 286 287 /** 288 * enum iwl_trans_status: transport status flags 289 * @STATUS_SYNC_HCMD_ACTIVE: a SYNC command is being processed 290 * @STATUS_DEVICE_ENABLED: APM is enabled 291 * @STATUS_TPOWER_PMI: the device might be asleep (need to wake it up) 292 * @STATUS_INT_ENABLED: interrupts are enabled 293 * @STATUS_RFKILL_HW: the actual HW state of the RF-kill switch 294 * @STATUS_RFKILL_OPMODE: RF-kill state reported to opmode 295 * @STATUS_FW_ERROR: the fw is in error state 296 * @STATUS_TRANS_DEAD: trans is dead - avoid any read/write operation 297 * @STATUS_SUPPRESS_CMD_ERROR_ONCE: suppress "FW error in SYNC CMD" once, 298 * e.g. for testing 299 * @STATUS_IN_SW_RESET: device is undergoing reset, cleared by opmode 300 * via iwl_trans_finish_sw_reset() 301 * @STATUS_RESET_PENDING: reset worker was scheduled, but didn't dump 302 * the firmware state yet 303 * @STATUS_TRANS_RESET_IN_PROGRESS: reset is still in progress, don't 304 * attempt another reset yet 305 * @STATUS_SUSPENDED: device is suspended, don't send commands that 306 * aren't marked accordingly 307 */ 308 enum iwl_trans_status { 309 STATUS_SYNC_HCMD_ACTIVE, 310 STATUS_DEVICE_ENABLED, 311 STATUS_TPOWER_PMI, 312 STATUS_INT_ENABLED, 313 STATUS_RFKILL_HW, 314 STATUS_RFKILL_OPMODE, 315 STATUS_FW_ERROR, 316 STATUS_TRANS_DEAD, 317 STATUS_SUPPRESS_CMD_ERROR_ONCE, 318 STATUS_IN_SW_RESET, 319 STATUS_RESET_PENDING, 320 STATUS_TRANS_RESET_IN_PROGRESS, 321 STATUS_SUSPENDED, 322 }; 323 324 static inline int 325 iwl_trans_get_rb_size_order(enum iwl_amsdu_size rb_size) 326 { 327 switch (rb_size) { 328 case IWL_AMSDU_2K: 329 return get_order(2 * 1024); 330 case IWL_AMSDU_4K: 331 return get_order(4 * 1024); 332 case IWL_AMSDU_8K: 333 return get_order(8 * 1024); 334 case IWL_AMSDU_12K: 335 return get_order(16 * 1024); 336 default: 337 WARN_ON(1); 338 return -1; 339 } 340 } 341 342 static inline int 343 iwl_trans_get_rb_size(enum iwl_amsdu_size rb_size) 344 { 345 switch (rb_size) { 346 case IWL_AMSDU_2K: 347 return 2 * 1024; 348 case IWL_AMSDU_4K: 349 return 4 * 1024; 350 case IWL_AMSDU_8K: 351 return 8 * 1024; 352 case IWL_AMSDU_12K: 353 return 16 * 1024; 354 default: 355 WARN_ON(1); 356 return 0; 357 } 358 } 359 360 struct iwl_hcmd_names { 361 u8 cmd_id; 362 const char *const cmd_name; 363 }; 364 365 #define HCMD_NAME(x) \ 366 { .cmd_id = x, .cmd_name = #x } 367 368 struct iwl_hcmd_arr { 369 const struct iwl_hcmd_names *arr; 370 int size; 371 }; 372 373 #define HCMD_ARR(x) \ 374 { .arr = x, .size = ARRAY_SIZE(x) } 375 376 /** 377 * struct iwl_dump_sanitize_ops - dump sanitization operations 378 * @frob_txf: Scrub the TX FIFO data 379 * @frob_hcmd: Scrub a host command, the %hcmd pointer is to the header 380 * but that might be short or long (&struct iwl_cmd_header or 381 * &struct iwl_cmd_header_wide) 382 * @frob_mem: Scrub memory data 383 */ 384 struct iwl_dump_sanitize_ops { 385 void (*frob_txf)(void *ctx, void *buf, size_t buflen); 386 void (*frob_hcmd)(void *ctx, void *hcmd, size_t buflen); 387 void (*frob_mem)(void *ctx, u32 mem_addr, void *mem, size_t buflen); 388 }; 389 390 /** 391 * struct iwl_trans_config - transport configuration 392 * 393 * These values should be set before iwl_trans_op_mode_enter(). 394 * 395 * @cmd_queue: the index of the command queue. 396 * Must be set before start_fw. 397 * @cmd_fifo: the fifo for host commands 398 * @no_reclaim_cmds: Some devices erroneously don't set the 399 * SEQ_RX_FRAME bit on some notifications, this is the 400 * list of such notifications to filter. Max length is 401 * %MAX_NO_RECLAIM_CMDS. 402 * @n_no_reclaim_cmds: # of commands in list 403 * @rx_buf_size: RX buffer size needed for A-MSDUs 404 * if unset 4k will be the RX buffer size 405 * @scd_set_active: should the transport configure the SCD for HCMD queue 406 * @command_groups: array of command groups, each member is an array of the 407 * commands in the group; for debugging only 408 * @command_groups_size: number of command groups, to avoid illegal access 409 * @cb_data_offs: offset inside skb->cb to store transport data at, must have 410 * space for at least two pointers 411 * @fw_reset_handshake: firmware supports reset flow handshake 412 * @queue_alloc_cmd_ver: queue allocation command version, set to 0 413 * for using the older SCD_QUEUE_CFG, set to the version of 414 * SCD_QUEUE_CONFIG_CMD otherwise. 415 * @wide_cmd_header: true when ucode supports wide command header format 416 * @rx_mpdu_cmd: MPDU RX command ID, must be assigned by opmode before 417 * starting the firmware, used for tracing 418 * @rx_mpdu_cmd_hdr_size: used for tracing, amount of data before the 419 * start of the 802.11 header in the @rx_mpdu_cmd 420 * @dsbr_urm_fw_dependent: switch to URM based on fw settings 421 * @dsbr_urm_permanent: switch to URM permanently 422 * @mbx_addr_0_step: step address data 0 423 * @mbx_addr_1_step: step address data 1 424 * @ext_32khz_clock_valid: if true, the external 32 KHz clock can be used 425 */ 426 struct iwl_trans_config { 427 u8 cmd_queue; 428 u8 cmd_fifo; 429 u8 n_no_reclaim_cmds; 430 u8 no_reclaim_cmds[MAX_NO_RECLAIM_CMDS]; 431 432 enum iwl_amsdu_size rx_buf_size; 433 bool scd_set_active; 434 const struct iwl_hcmd_arr *command_groups; 435 int command_groups_size; 436 437 u8 cb_data_offs; 438 bool fw_reset_handshake; 439 u8 queue_alloc_cmd_ver; 440 441 bool wide_cmd_header; 442 u8 rx_mpdu_cmd, rx_mpdu_cmd_hdr_size; 443 444 u8 dsbr_urm_fw_dependent:1, 445 dsbr_urm_permanent:1, 446 ext_32khz_clock_valid:1; 447 448 u32 mbx_addr_0_step; 449 u32 mbx_addr_1_step; 450 }; 451 452 struct iwl_trans_dump_data { 453 u32 len; 454 u8 data[]; 455 }; 456 457 struct iwl_trans; 458 459 struct iwl_trans_txq_scd_cfg { 460 u8 fifo; 461 u8 sta_id; 462 u8 tid; 463 bool aggregate; 464 int frame_limit; 465 }; 466 467 /** 468 * struct iwl_trans_rxq_dma_data - RX queue DMA data 469 * @fr_bd_cb: DMA address of free BD cyclic buffer 470 * @fr_bd_wid: Initial write index of the free BD cyclic buffer 471 * @urbd_stts_wrptr: DMA address of urbd_stts_wrptr 472 * @ur_bd_cb: DMA address of used BD cyclic buffer 473 */ 474 struct iwl_trans_rxq_dma_data { 475 u64 fr_bd_cb; 476 u32 fr_bd_wid; 477 u64 urbd_stts_wrptr; 478 u64 ur_bd_cb; 479 }; 480 481 /* maximal number of DRAM MAP entries supported by FW */ 482 #define IPC_DRAM_MAP_ENTRY_NUM_MAX 64 483 484 /** 485 * struct iwl_pnvm_image - contains info about the parsed pnvm image 486 * @chunks: array of pointers to pnvm payloads and their sizes 487 * @n_chunks: the number of the pnvm payloads. 488 * @version: the version of the loaded PNVM image 489 */ 490 struct iwl_pnvm_image { 491 struct { 492 const void *data; 493 u32 len; 494 } chunks[IPC_DRAM_MAP_ENTRY_NUM_MAX]; 495 u32 n_chunks; 496 u32 version; 497 }; 498 499 /** 500 * enum iwl_trans_state - state of the transport layer 501 * 502 * @IWL_TRANS_NO_FW: firmware wasn't started yet, or crashed 503 * @IWL_TRANS_FW_STARTED: FW was started, but not alive yet 504 * @IWL_TRANS_FW_ALIVE: FW has sent an alive response 505 */ 506 enum iwl_trans_state { 507 IWL_TRANS_NO_FW, 508 IWL_TRANS_FW_STARTED, 509 IWL_TRANS_FW_ALIVE, 510 }; 511 512 /** 513 * DOC: Platform power management 514 * 515 * In system-wide power management the entire platform goes into a low 516 * power state (e.g. idle or suspend to RAM) at the same time and the 517 * device is configured as a wakeup source for the entire platform. 518 * This is usually triggered by userspace activity (e.g. the user 519 * presses the suspend button or a power management daemon decides to 520 * put the platform in low power mode). The device's behavior in this 521 * mode is dictated by the wake-on-WLAN configuration. 522 * 523 * The terms used for the device's behavior are as follows: 524 * 525 * - D0: the device is fully powered and the host is awake; 526 * - D3: the device is in low power mode and only reacts to 527 * specific events (e.g. magic-packet received or scan 528 * results found); 529 * 530 * These terms reflect the power modes in the firmware and are not to 531 * be confused with the physical device power state. 532 */ 533 534 /** 535 * enum iwl_ini_cfg_state 536 * @IWL_INI_CFG_STATE_NOT_LOADED: no debug cfg was given 537 * @IWL_INI_CFG_STATE_LOADED: debug cfg was found and loaded 538 * @IWL_INI_CFG_STATE_CORRUPTED: debug cfg was found and some of the TLVs 539 * are corrupted. The rest of the debug TLVs will still be used 540 */ 541 enum iwl_ini_cfg_state { 542 IWL_INI_CFG_STATE_NOT_LOADED, 543 IWL_INI_CFG_STATE_LOADED, 544 IWL_INI_CFG_STATE_CORRUPTED, 545 }; 546 547 /* Max time to wait for nmi interrupt */ 548 #define IWL_TRANS_NMI_TIMEOUT (HZ / 4) 549 550 /** 551 * struct iwl_dram_data 552 * @physical: page phy pointer 553 * @block: pointer to the allocated block/page 554 * @size: size of the block/page 555 */ 556 struct iwl_dram_data { 557 dma_addr_t physical; 558 void *block; 559 int size; 560 }; 561 562 /** 563 * struct iwl_dram_regions - DRAM regions container structure 564 * @drams: array of several DRAM areas that contains the pnvm and power 565 * reduction table payloads. 566 * @n_regions: number of DRAM regions that were allocated 567 * @prph_scratch_mem_desc: points to a structure allocated in dram, 568 * designed to show FW where all the payloads are. 569 */ 570 struct iwl_dram_regions { 571 struct iwl_dram_data drams[IPC_DRAM_MAP_ENTRY_NUM_MAX]; 572 struct iwl_dram_data prph_scratch_mem_desc; 573 u8 n_regions; 574 }; 575 576 /** 577 * struct iwl_fw_mon - fw monitor per allocation id 578 * @num_frags: number of fragments 579 * @frags: an array of DRAM buffer fragments 580 */ 581 struct iwl_fw_mon { 582 u32 num_frags; 583 struct iwl_dram_data *frags; 584 }; 585 586 /** 587 * struct iwl_self_init_dram - dram data used by self init process 588 * @fw: lmac and umac dram data 589 * @fw_cnt: total number of items in array 590 * @paging: paging dram data 591 * @paging_cnt: total number of items in array 592 */ 593 struct iwl_self_init_dram { 594 struct iwl_dram_data *fw; 595 int fw_cnt; 596 struct iwl_dram_data *paging; 597 int paging_cnt; 598 }; 599 600 /** 601 * struct iwl_imr_data - imr dram data used during debug process 602 * @imr_enable: imr enable status received from fw 603 * @imr_size: imr dram size received from fw 604 * @sram_addr: sram address from debug tlv 605 * @sram_size: sram size from debug tlv 606 * @imr2sram_remainbyte: size remained after each dma transfer 607 * @imr_curr_addr: current dst address used during dma transfer 608 * @imr_base_addr: imr address received from fw 609 */ 610 struct iwl_imr_data { 611 u32 imr_enable; 612 u32 imr_size; 613 u32 sram_addr; 614 u32 sram_size; 615 u32 imr2sram_remainbyte; 616 u64 imr_curr_addr; 617 __le64 imr_base_addr; 618 }; 619 620 #define IWL_TRANS_CURRENT_PC_NAME_MAX_BYTES 32 621 622 /** 623 * struct iwl_pc_data - program counter details 624 * @pc_name: cpu name 625 * @pc_address: cpu program counter 626 */ 627 struct iwl_pc_data { 628 u8 pc_name[IWL_TRANS_CURRENT_PC_NAME_MAX_BYTES]; 629 u32 pc_address; 630 }; 631 632 /** 633 * struct iwl_trans_debug - transport debug related data 634 * 635 * @n_dest_reg: num of reg_ops in %dbg_dest_tlv 636 * @rec_on: true iff there is a fw debug recording currently active 637 * @dest_tlv: points to the destination TLV for debug 638 * @lmac_error_event_table: addrs of lmacs error tables 639 * @umac_error_event_table: addr of umac error table 640 * @tcm_error_event_table: address(es) of TCM error table(s) 641 * @rcm_error_event_table: address(es) of RCM error table(s) 642 * @error_event_table_tlv_status: bitmap that indicates what error table 643 * pointers was recevied via TLV. uses enum &iwl_error_event_table_status 644 * @internal_ini_cfg: internal debug cfg state. Uses &enum iwl_ini_cfg_state 645 * @external_ini_cfg: external debug cfg state. Uses &enum iwl_ini_cfg_state 646 * @fw_mon_cfg: debug buffer allocation configuration 647 * @fw_mon_ini: DRAM buffer fragments per allocation id 648 * @fw_mon: DRAM buffer for firmware monitor 649 * @hw_error: equals true if hw error interrupt was received from the FW 650 * @ini_dest: debug monitor destination uses &enum iwl_fw_ini_buffer_location 651 * @unsupported_region_msk: unsupported regions out of active_regions 652 * @active_regions: active regions 653 * @debug_info_tlv_list: list of debug info TLVs 654 * @time_point: array of debug time points 655 * @periodic_trig_list: periodic triggers list 656 * @domains_bitmap: bitmap of active domains other than &IWL_FW_INI_DOMAIN_ALWAYS_ON 657 * @ucode_preset: preset based on ucode 658 * @restart_required: indicates debug restart is required 659 * @last_tp_resetfw: last handling of reset during debug timepoint 660 * @imr_data: IMR debug data allocation 661 * @dump_file_name_ext: dump file name extension 662 * @dump_file_name_ext_valid: dump file name extension if valid or not 663 * @num_pc: number of program counter for cpu 664 * @pc_data: details of the program counter 665 * @yoyo_bin_loaded: tells if a yoyo debug file has been loaded 666 */ 667 struct iwl_trans_debug { 668 u8 n_dest_reg; 669 bool rec_on; 670 671 const struct iwl_fw_dbg_dest_tlv_v1 *dest_tlv; 672 673 u32 lmac_error_event_table[2]; 674 u32 umac_error_event_table; 675 u32 tcm_error_event_table[2]; 676 u32 rcm_error_event_table[2]; 677 unsigned int error_event_table_tlv_status; 678 679 enum iwl_ini_cfg_state internal_ini_cfg; 680 enum iwl_ini_cfg_state external_ini_cfg; 681 682 struct iwl_fw_ini_allocation_tlv fw_mon_cfg[IWL_FW_INI_ALLOCATION_NUM]; 683 struct iwl_fw_mon fw_mon_ini[IWL_FW_INI_ALLOCATION_NUM]; 684 685 struct iwl_dram_data fw_mon; 686 687 bool hw_error; 688 enum iwl_fw_ini_buffer_location ini_dest; 689 690 u64 unsupported_region_msk; 691 struct iwl_ucode_tlv *active_regions[IWL_FW_INI_MAX_REGION_ID]; 692 struct list_head debug_info_tlv_list; 693 struct iwl_dbg_tlv_time_point_data time_point[IWL_FW_INI_TIME_POINT_NUM]; 694 struct list_head periodic_trig_list; 695 696 u32 domains_bitmap; 697 u32 ucode_preset; 698 bool restart_required; 699 u32 last_tp_resetfw; 700 struct iwl_imr_data imr_data; 701 u8 dump_file_name_ext[IWL_FW_INI_MAX_NAME]; 702 bool dump_file_name_ext_valid; 703 u32 num_pc; 704 struct iwl_pc_data *pc_data; 705 bool yoyo_bin_loaded; 706 }; 707 708 struct iwl_dma_ptr { 709 dma_addr_t dma; 710 void *addr; 711 size_t size; 712 }; 713 714 struct iwl_cmd_meta { 715 /* only for SYNC commands, iff the reply skb is wanted */ 716 struct iwl_host_cmd *source; 717 u32 flags: CMD_MODE_BITS; 718 /* sg_offset is valid if it is non-zero */ 719 u32 sg_offset: PAGE_SHIFT; 720 u32 tbs; 721 }; 722 723 /* 724 * The FH will write back to the first TB only, so we need to copy some data 725 * into the buffer regardless of whether it should be mapped or not. 726 * This indicates how big the first TB must be to include the scratch buffer 727 * and the assigned PN. 728 * Since PN location is 8 bytes at offset 12, it's 20 now. 729 * If we make it bigger then allocations will be bigger and copy slower, so 730 * that's probably not useful. 731 */ 732 #define IWL_FIRST_TB_SIZE 20 733 #define IWL_FIRST_TB_SIZE_ALIGN ALIGN(IWL_FIRST_TB_SIZE, 64) 734 735 struct iwl_pcie_txq_entry { 736 void *cmd; 737 struct sk_buff *skb; 738 /* buffer to free after command completes */ 739 const void *free_buf; 740 struct iwl_cmd_meta meta; 741 }; 742 743 struct iwl_pcie_first_tb_buf { 744 u8 buf[IWL_FIRST_TB_SIZE_ALIGN]; 745 }; 746 747 /** 748 * struct iwl_txq - Tx Queue for DMA 749 * @tfds: transmit frame descriptors (DMA memory) 750 * @first_tb_bufs: start of command headers, including scratch buffers, for 751 * the writeback -- this is DMA memory and an array holding one buffer 752 * for each command on the queue 753 * @first_tb_dma: DMA address for the first_tb_bufs start 754 * @entries: transmit entries (driver state) 755 * @lock: queue lock 756 * @reclaim_lock: reclaim lock 757 * @stuck_timer: timer that fires if queue gets stuck 758 * @trans: pointer back to transport (for timer) 759 * @need_update: indicates need to update read/write index 760 * @ampdu: true if this queue is an ampdu queue for an specific RA/TID 761 * @wd_timeout: queue watchdog timeout (jiffies) - per queue 762 * @frozen: tx stuck queue timer is frozen 763 * @frozen_expiry_remainder: remember how long until the timer fires 764 * @block: queue is blocked 765 * @bc_tbl: byte count table of the queue (relevant only for gen2 transport) 766 * @write_ptr: 1-st empty entry (index) host_w 767 * @read_ptr: last used entry (index) host_r 768 * @dma_addr: physical addr for BD's 769 * @n_window: safe queue window 770 * @id: queue id 771 * @low_mark: low watermark, resume queue if free space more than this 772 * @high_mark: high watermark, stop queue if free space less than this 773 * @overflow_q: overflow queue for handling frames that didn't fit on HW queue 774 * @overflow_tx: need to transmit from overflow 775 * 776 * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame 777 * descriptors) and required locking structures. 778 * 779 * Note the difference between TFD_QUEUE_SIZE_MAX and n_window: the hardware 780 * always assumes 256 descriptors, so TFD_QUEUE_SIZE_MAX is always 256 (unless 781 * there might be HW changes in the future). For the normal TX 782 * queues, n_window, which is the size of the software queue data 783 * is also 256; however, for the command queue, n_window is only 784 * 32 since we don't need so many commands pending. Since the HW 785 * still uses 256 BDs for DMA though, TFD_QUEUE_SIZE_MAX stays 256. 786 * This means that we end up with the following: 787 * HW entries: | 0 | ... | N * 32 | ... | N * 32 + 31 | ... | 255 | 788 * SW entries: | 0 | ... | 31 | 789 * where N is a number between 0 and 7. This means that the SW 790 * data is a window overlayed over the HW queue. 791 */ 792 struct iwl_txq { 793 void *tfds; 794 struct iwl_pcie_first_tb_buf *first_tb_bufs; 795 dma_addr_t first_tb_dma; 796 struct iwl_pcie_txq_entry *entries; 797 /* lock for syncing changes on the queue */ 798 spinlock_t lock; 799 /* lock to prevent concurrent reclaim */ 800 spinlock_t reclaim_lock; 801 unsigned long frozen_expiry_remainder; 802 struct timer_list stuck_timer; 803 struct iwl_trans *trans; 804 bool need_update; 805 bool frozen; 806 bool ampdu; 807 int block; 808 unsigned long wd_timeout; 809 struct sk_buff_head overflow_q; 810 struct iwl_dma_ptr bc_tbl; 811 812 int write_ptr; 813 int read_ptr; 814 dma_addr_t dma_addr; 815 int n_window; 816 u32 id; 817 int low_mark; 818 int high_mark; 819 820 bool overflow_tx; 821 }; 822 823 /** 824 * struct iwl_trans_info - transport info for outside use 825 * @name: the device name 826 * @max_skb_frags: maximum number of fragments an SKB can have when transmitted. 827 * 0 indicates that frag SKBs (NETIF_F_SG) aren't supported. 828 * @hw_rev: the revision data of the HW 829 * @hw_rev_step: The mac step of the HW 830 * @hw_rf_id: the device RF ID 831 * @hw_cnv_id: the device CNV ID 832 * @hw_crf_id: the device CRF ID 833 * @hw_wfpm_id: the device wfpm ID 834 * @hw_id: the ID of the device / sub-device 835 * Bits 0:15 represent the sub-device ID 836 * Bits 16:31 represent the device ID. 837 * @pcie_link_speed: current PCIe link speed (%PCI_EXP_LNKSTA_CLS_*), 838 * only valid for discrete (not integrated) NICs 839 * @num_rxqs: number of RX queues allocated by the transport 840 */ 841 struct iwl_trans_info { 842 const char *name; 843 u32 max_skb_frags; 844 u32 hw_rev; 845 u32 hw_rev_step; 846 u32 hw_rf_id; 847 u32 hw_crf_id; 848 u32 hw_cnv_id; 849 u32 hw_wfpm_id; 850 u32 hw_id; 851 u8 pcie_link_speed; 852 u8 num_rxqs; 853 }; 854 855 /** 856 * struct iwl_trans - transport common data 857 * 858 * @csme_own: true if we couldn't get ownership on the device 859 * @op_mode: pointer to the op_mode 860 * @mac_cfg: the trans-specific configuration part 861 * @cfg: pointer to the configuration 862 * @drv: pointer to iwl_drv 863 * @conf: configuration set by the opmode before enter 864 * @state: current device state 865 * @status: a bit-mask of transport status flags 866 * @dev: pointer to struct device * that represents the device 867 * @info: device information for use by other layers 868 * @pnvm_loaded: indicates PNVM was loaded 869 * @pm_support: set to true in start_hw if link pm is supported 870 * @ltr_enabled: set to true if the LTR is enabled 871 * @fail_to_parse_pnvm_image: set to true if pnvm parsing failed 872 * @reduce_power_loaded: indicates reduced power section was loaded 873 * @failed_to_load_reduce_power_image: set to true if pnvm loading failed 874 * @dev_cmd_pool: pool for Tx cmd allocation - for internal use only. 875 * The user should use iwl_trans_{alloc,free}_tx_cmd. 876 * @dev_cmd_pool_name: name for the TX command allocation pool 877 * @dbgfs_dir: iwlwifi debugfs base dir for this device 878 * @sync_cmd_lockdep_map: lockdep map for checking sync commands 879 * @dbg: additional debug data, see &struct iwl_trans_debug 880 * @init_dram: FW initialization DMA data 881 * @reduced_cap_sku: reduced capability supported SKU 882 * @step_urm: STEP is in URM, no support for MCS>9 in 320 MHz 883 * @restart: restart worker data 884 * @restart.wk: restart worker 885 * @restart.mode: reset/restart error mode information 886 * @restart.during_reset: error occurred during previous software reset 887 * @trans_specific: data for the specific transport this is allocated for/with 888 * @request_top_reset: TOP reset was requested, used by the reset 889 * worker that should be scheduled (with appropriate reason) 890 * @do_top_reset: indication to the (PCIe) transport/context-info 891 * to do the TOP reset 892 */ 893 struct iwl_trans { 894 bool csme_own; 895 struct iwl_op_mode *op_mode; 896 const struct iwl_mac_cfg *mac_cfg; 897 const struct iwl_rf_cfg *cfg; 898 struct iwl_drv *drv; 899 struct iwl_trans_config conf; 900 enum iwl_trans_state state; 901 unsigned long status; 902 903 struct device *dev; 904 905 const struct iwl_trans_info info; 906 bool reduced_cap_sku; 907 bool step_urm; 908 909 bool pm_support; 910 bool ltr_enabled; 911 u8 pnvm_loaded:1; 912 u8 fail_to_parse_pnvm_image:1; 913 u8 reduce_power_loaded:1; 914 u8 failed_to_load_reduce_power_image:1; 915 916 /* The following fields are internal only */ 917 struct kmem_cache *dev_cmd_pool; 918 char dev_cmd_pool_name[50]; 919 920 struct dentry *dbgfs_dir; 921 922 #ifdef CONFIG_LOCKDEP 923 struct lockdep_map sync_cmd_lockdep_map; 924 #endif 925 926 struct iwl_trans_debug dbg; 927 struct iwl_self_init_dram init_dram; 928 929 struct { 930 struct delayed_work wk; 931 struct iwl_fw_error_dump_mode mode; 932 bool during_reset; 933 } restart; 934 935 u8 request_top_reset:1, 936 do_top_reset:1; 937 938 /* pointer to trans specific struct */ 939 /*Ensure that this pointer will always be aligned to sizeof pointer */ 940 char trans_specific[] __aligned(sizeof(void *)); 941 }; 942 943 const char *iwl_get_cmd_string(struct iwl_trans *trans, u32 id); 944 945 void iwl_trans_op_mode_enter(struct iwl_trans *trans, 946 struct iwl_op_mode *op_mode); 947 948 int iwl_trans_start_hw(struct iwl_trans *trans); 949 950 void iwl_trans_op_mode_leave(struct iwl_trans *trans); 951 952 void iwl_trans_fw_alive(struct iwl_trans *trans); 953 954 int iwl_trans_start_fw(struct iwl_trans *trans, const struct iwl_fw *fw, 955 enum iwl_ucode_type ucode_type, bool run_in_rfkill); 956 957 void iwl_trans_stop_device(struct iwl_trans *trans); 958 959 int iwl_trans_d3_suspend(struct iwl_trans *trans, bool test, bool reset); 960 961 int iwl_trans_d3_resume(struct iwl_trans *trans, enum iwl_d3_status *status, 962 bool test, bool reset); 963 964 struct iwl_trans_dump_data * 965 iwl_trans_dump_data(struct iwl_trans *trans, u32 dump_mask, 966 const struct iwl_dump_sanitize_ops *sanitize_ops, 967 void *sanitize_ctx); 968 969 static inline struct iwl_device_tx_cmd * 970 iwl_trans_alloc_tx_cmd(struct iwl_trans *trans) 971 { 972 return kmem_cache_zalloc(trans->dev_cmd_pool, GFP_ATOMIC); 973 } 974 975 int iwl_trans_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd); 976 977 static inline void iwl_trans_free_tx_cmd(struct iwl_trans *trans, 978 struct iwl_device_tx_cmd *dev_cmd) 979 { 980 kmem_cache_free(trans->dev_cmd_pool, dev_cmd); 981 } 982 983 int iwl_trans_tx(struct iwl_trans *trans, struct sk_buff *skb, 984 struct iwl_device_tx_cmd *dev_cmd, int queue); 985 986 void iwl_trans_reclaim(struct iwl_trans *trans, int queue, int ssn, 987 struct sk_buff_head *skbs, bool is_flush); 988 989 void iwl_trans_set_q_ptrs(struct iwl_trans *trans, int queue, int ptr); 990 991 void iwl_trans_txq_disable(struct iwl_trans *trans, int queue, 992 bool configure_scd); 993 994 bool iwl_trans_txq_enable_cfg(struct iwl_trans *trans, int queue, u16 ssn, 995 const struct iwl_trans_txq_scd_cfg *cfg, 996 unsigned int queue_wdg_timeout); 997 998 int iwl_trans_get_rxq_dma_data(struct iwl_trans *trans, int queue, 999 struct iwl_trans_rxq_dma_data *data); 1000 1001 void iwl_trans_txq_free(struct iwl_trans *trans, int queue); 1002 1003 int iwl_trans_txq_alloc(struct iwl_trans *trans, u32 flags, u32 sta_mask, 1004 u8 tid, int size, unsigned int wdg_timeout); 1005 1006 void iwl_trans_txq_set_shared_mode(struct iwl_trans *trans, 1007 int txq_id, bool shared_mode); 1008 1009 static inline void iwl_trans_txq_enable(struct iwl_trans *trans, int queue, 1010 int fifo, int sta_id, int tid, 1011 int frame_limit, u16 ssn, 1012 unsigned int queue_wdg_timeout) 1013 { 1014 struct iwl_trans_txq_scd_cfg cfg = { 1015 .fifo = fifo, 1016 .sta_id = sta_id, 1017 .tid = tid, 1018 .frame_limit = frame_limit, 1019 .aggregate = sta_id >= 0, 1020 }; 1021 1022 iwl_trans_txq_enable_cfg(trans, queue, ssn, &cfg, queue_wdg_timeout); 1023 } 1024 1025 static inline 1026 void iwl_trans_ac_txq_enable(struct iwl_trans *trans, int queue, int fifo, 1027 unsigned int queue_wdg_timeout) 1028 { 1029 struct iwl_trans_txq_scd_cfg cfg = { 1030 .fifo = fifo, 1031 .sta_id = -1, 1032 .tid = IWL_MAX_TID_COUNT, 1033 .frame_limit = IWL_FRAME_LIMIT, 1034 .aggregate = false, 1035 }; 1036 1037 iwl_trans_txq_enable_cfg(trans, queue, 0, &cfg, queue_wdg_timeout); 1038 } 1039 1040 void iwl_trans_freeze_txq_timer(struct iwl_trans *trans, 1041 unsigned long txqs, bool freeze); 1042 1043 int iwl_trans_wait_tx_queues_empty(struct iwl_trans *trans, u32 txqs); 1044 1045 int iwl_trans_wait_txq_empty(struct iwl_trans *trans, int queue); 1046 1047 void iwl_trans_write8(struct iwl_trans *trans, u32 ofs, u8 val); 1048 1049 void iwl_trans_write32(struct iwl_trans *trans, u32 ofs, u32 val); 1050 1051 u32 iwl_trans_read32(struct iwl_trans *trans, u32 ofs); 1052 1053 u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs); 1054 1055 void iwl_trans_write_prph(struct iwl_trans *trans, u32 ofs, u32 val); 1056 1057 int iwl_trans_read_mem(struct iwl_trans *trans, u32 addr, 1058 void *buf, int dwords); 1059 1060 int iwl_trans_read_config32(struct iwl_trans *trans, u32 ofs, 1061 u32 *val); 1062 1063 #ifdef CONFIG_IWLWIFI_DEBUGFS 1064 void iwl_trans_debugfs_cleanup(struct iwl_trans *trans); 1065 #endif 1066 1067 #define iwl_trans_read_mem_bytes(trans, addr, buf, bufsize) \ 1068 ({ \ 1069 if (__builtin_constant_p(bufsize)) \ 1070 BUILD_BUG_ON((bufsize) % sizeof(u32)); \ 1071 iwl_trans_read_mem(trans, addr, buf, \ 1072 (bufsize) / sizeof(u32)); \ 1073 }) 1074 1075 int iwl_trans_write_imr_mem(struct iwl_trans *trans, u32 dst_addr, 1076 u64 src_addr, u32 byte_cnt); 1077 1078 static inline u32 iwl_trans_read_mem32(struct iwl_trans *trans, u32 addr) 1079 { 1080 u32 value; 1081 1082 if (iwl_trans_read_mem(trans, addr, &value, 1)) 1083 return 0xa5a5a5a5; 1084 1085 return value; 1086 } 1087 1088 int iwl_trans_write_mem(struct iwl_trans *trans, u32 addr, 1089 const void *buf, int dwords); 1090 1091 static inline u32 iwl_trans_write_mem32(struct iwl_trans *trans, u32 addr, 1092 u32 val) 1093 { 1094 return iwl_trans_write_mem(trans, addr, &val, 1); 1095 } 1096 1097 void iwl_trans_set_pmi(struct iwl_trans *trans, bool state); 1098 1099 int iwl_trans_sw_reset(struct iwl_trans *trans, bool retake_ownership); 1100 1101 void iwl_trans_set_bits_mask(struct iwl_trans *trans, u32 reg, 1102 u32 mask, u32 value); 1103 1104 bool _iwl_trans_grab_nic_access(struct iwl_trans *trans); 1105 1106 #define iwl_trans_grab_nic_access(trans) \ 1107 __cond_lock(nic_access, \ 1108 likely(_iwl_trans_grab_nic_access(trans))) 1109 1110 void __releases(nic_access) 1111 iwl_trans_release_nic_access(struct iwl_trans *trans); 1112 1113 static inline void iwl_trans_schedule_reset(struct iwl_trans *trans, 1114 enum iwl_fw_error_type type) 1115 { 1116 if (test_bit(STATUS_TRANS_DEAD, &trans->status)) 1117 return; 1118 /* clear this on device init, not cleared on any unbind/reprobe */ 1119 if (test_and_set_bit(STATUS_TRANS_RESET_IN_PROGRESS, &trans->status)) 1120 return; 1121 1122 trans->restart.mode.type = type; 1123 trans->restart.mode.context = IWL_ERR_CONTEXT_WORKER; 1124 1125 set_bit(STATUS_RESET_PENDING, &trans->status); 1126 1127 /* 1128 * keep track of whether or not this happened while resetting, 1129 * by the timer the worker runs it might have finished 1130 */ 1131 trans->restart.during_reset = test_bit(STATUS_IN_SW_RESET, 1132 &trans->status); 1133 queue_delayed_work(system_unbound_wq, &trans->restart.wk, 0); 1134 } 1135 1136 static inline void iwl_trans_fw_error(struct iwl_trans *trans, 1137 enum iwl_fw_error_type type) 1138 { 1139 if (WARN_ON_ONCE(!trans->op_mode)) 1140 return; 1141 1142 /* prevent double restarts due to the same erroneous FW */ 1143 if (!test_and_set_bit(STATUS_FW_ERROR, &trans->status)) { 1144 trans->state = IWL_TRANS_NO_FW; 1145 iwl_op_mode_nic_error(trans->op_mode, type); 1146 iwl_trans_schedule_reset(trans, type); 1147 } 1148 } 1149 1150 static inline void iwl_trans_opmode_sw_reset(struct iwl_trans *trans, 1151 enum iwl_fw_error_type type) 1152 { 1153 if (WARN_ON_ONCE(!trans->op_mode)) 1154 return; 1155 1156 set_bit(STATUS_IN_SW_RESET, &trans->status); 1157 1158 if (WARN_ON(type == IWL_ERR_TYPE_TOP_RESET_BY_BT)) 1159 return; 1160 1161 if (!trans->op_mode->ops->sw_reset || 1162 !trans->op_mode->ops->sw_reset(trans->op_mode, type)) 1163 clear_bit(STATUS_IN_SW_RESET, &trans->status); 1164 } 1165 1166 static inline bool iwl_trans_fw_running(struct iwl_trans *trans) 1167 { 1168 return trans->state == IWL_TRANS_FW_ALIVE; 1169 } 1170 1171 void iwl_trans_sync_nmi(struct iwl_trans *trans); 1172 1173 void iwl_trans_sync_nmi_with_addr(struct iwl_trans *trans, u32 inta_addr, 1174 u32 sw_err_bit); 1175 1176 int iwl_trans_load_pnvm(struct iwl_trans *trans, 1177 const struct iwl_pnvm_image *pnvm_data, 1178 const struct iwl_ucode_capabilities *capa); 1179 1180 void iwl_trans_set_pnvm(struct iwl_trans *trans, 1181 const struct iwl_ucode_capabilities *capa); 1182 1183 int iwl_trans_load_reduce_power(struct iwl_trans *trans, 1184 const struct iwl_pnvm_image *payloads, 1185 const struct iwl_ucode_capabilities *capa); 1186 1187 void iwl_trans_set_reduce_power(struct iwl_trans *trans, 1188 const struct iwl_ucode_capabilities *capa); 1189 1190 static inline bool iwl_trans_dbg_ini_valid(struct iwl_trans *trans) 1191 { 1192 return trans->dbg.internal_ini_cfg != IWL_INI_CFG_STATE_NOT_LOADED || 1193 trans->dbg.external_ini_cfg != IWL_INI_CFG_STATE_NOT_LOADED; 1194 } 1195 1196 void iwl_trans_interrupts(struct iwl_trans *trans, bool enable); 1197 1198 static inline void iwl_trans_finish_sw_reset(struct iwl_trans *trans) 1199 { 1200 clear_bit(STATUS_IN_SW_RESET, &trans->status); 1201 } 1202 1203 /***************************************************** 1204 * transport helper functions 1205 *****************************************************/ 1206 struct iwl_trans *iwl_trans_alloc(unsigned int priv_size, 1207 struct device *dev, 1208 const struct iwl_mac_cfg *cfg_trans); 1209 int iwl_trans_init(struct iwl_trans *trans); 1210 void iwl_trans_free(struct iwl_trans *trans); 1211 1212 static inline bool iwl_trans_is_hw_error_value(u32 val) 1213 { 1214 return ((val & ~0xf) == 0xa5a5a5a0) || ((val & ~0xf) == 0x5a5a5a50); 1215 } 1216 1217 void iwl_trans_free_restart_list(void); 1218 1219 static inline u16 iwl_trans_get_num_rbds(struct iwl_trans *trans) 1220 { 1221 u16 result = trans->cfg->num_rbds; 1222 1223 /* 1224 * Since AX210 family (So/Ty) the device cannot put mutliple 1225 * frames into the same buffer, so double the value for them. 1226 */ 1227 if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) 1228 return 2 * result; 1229 return result; 1230 } 1231 1232 /***************************************************** 1233 * PCIe handling 1234 *****************************************************/ 1235 int __must_check iwl_pci_register_driver(void); 1236 void iwl_pci_unregister_driver(void); 1237 1238 /* Note: order matters */ 1239 enum iwl_reset_mode { 1240 /* upper level modes: */ 1241 IWL_RESET_MODE_SW_RESET, 1242 IWL_RESET_MODE_REPROBE, 1243 /* TOP reset doesn't require PCIe remove */ 1244 IWL_RESET_MODE_TOP_RESET, 1245 /* PCIE level modes: */ 1246 IWL_RESET_MODE_REMOVE_ONLY, 1247 IWL_RESET_MODE_RESCAN, 1248 IWL_RESET_MODE_FUNC_RESET, 1249 IWL_RESET_MODE_PROD_RESET, 1250 1251 /* keep last - special backoff value */ 1252 IWL_RESET_MODE_BACKOFF, 1253 }; 1254 1255 void iwl_trans_pcie_reset(struct iwl_trans *trans, enum iwl_reset_mode mode); 1256 void iwl_trans_pcie_fw_reset_handshake(struct iwl_trans *trans); 1257 1258 int iwl_trans_pcie_send_hcmd(struct iwl_trans *trans, 1259 struct iwl_host_cmd *cmd); 1260 1261 /* Internal helper */ 1262 static inline void iwl_trans_set_info(struct iwl_trans *trans, 1263 struct iwl_trans_info *info) 1264 { 1265 struct iwl_trans_info *write; 1266 1267 write = (void *)(uintptr_t)&trans->info; 1268 *write = *info; 1269 } 1270 1271 static inline u16 iwl_trans_get_device_id(struct iwl_trans *trans) 1272 { 1273 return u32_get_bits(trans->info.hw_id, GENMASK(31, 16)); 1274 } 1275 1276 #endif /* __iwl_trans_h__ */ 1277