18e99ea8dSJohannes Berg /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ 28e99ea8dSJohannes Berg /* 385b17a33SJohannes Berg * Copyright (C) 2005-2014, 2018-2022 Intel Corporation 48e99ea8dSJohannes Berg * Copyright (C) 2013-2015 Intel Mobile Communications GmbH 58e99ea8dSJohannes Berg * Copyright (C) 2016-2017 Intel Deutschland GmbH 68e99ea8dSJohannes Berg */ 7e705c121SKalle Valo #ifndef __iwl_trans_h__ 8e705c121SKalle Valo #define __iwl_trans_h__ 9e705c121SKalle Valo 10e705c121SKalle Valo #include <linux/ieee80211.h> 11e705c121SKalle Valo #include <linux/mm.h> /* for page_address */ 12e705c121SKalle Valo #include <linux/lockdep.h> 1339bdb17eSSharon Dvir #include <linux/kernel.h> 14e705c121SKalle Valo 15e705c121SKalle Valo #include "iwl-debug.h" 16e705c121SKalle Valo #include "iwl-config.h" 17d962f9b1SJohannes Berg #include "fw/img.h" 18e705c121SKalle Valo #include "iwl-op-mode.h" 1969725928SLuca Coelho #include <linux/firmware.h> 20d172a5efSJohannes Berg #include "fw/api/cmdhdr.h" 21d172a5efSJohannes Berg #include "fw/api/txq.h" 22f14cda6fSSara Sharon #include "fw/api/dbg-tlv.h" 23f14cda6fSSara Sharon #include "iwl-dbg-tlv.h" 24e705c121SKalle Valo 25e705c121SKalle Valo /** 26e705c121SKalle Valo * DOC: Transport layer - what is it ? 27e705c121SKalle Valo * 28e705c121SKalle Valo * The transport layer is the layer that deals with the HW directly. It provides 29e705c121SKalle Valo * an abstraction of the underlying HW to the upper layer. The transport layer 30e705c121SKalle Valo * doesn't provide any policy, algorithm or anything of this kind, but only 31e705c121SKalle Valo * mechanisms to make the HW do something. It is not completely stateless but 32e705c121SKalle Valo * close to it. 33e705c121SKalle Valo * We will have an implementation for each different supported bus. 34e705c121SKalle Valo */ 35e705c121SKalle Valo 36e705c121SKalle Valo /** 37e705c121SKalle Valo * DOC: Life cycle of the transport layer 38e705c121SKalle Valo * 39e705c121SKalle Valo * The transport layer has a very precise life cycle. 40e705c121SKalle Valo * 41e705c121SKalle Valo * 1) A helper function is called during the module initialization and 42e705c121SKalle Valo * registers the bus driver's ops with the transport's alloc function. 43e705c121SKalle Valo * 2) Bus's probe calls to the transport layer's allocation functions. 44e705c121SKalle Valo * Of course this function is bus specific. 45e705c121SKalle Valo * 3) This allocation functions will spawn the upper layer which will 46e705c121SKalle Valo * register mac80211. 47e705c121SKalle Valo * 48e705c121SKalle Valo * 4) At some point (i.e. mac80211's start call), the op_mode will call 49e705c121SKalle Valo * the following sequence: 50e705c121SKalle Valo * start_hw 51e705c121SKalle Valo * start_fw 52e705c121SKalle Valo * 53e705c121SKalle Valo * 5) Then when finished (or reset): 54e705c121SKalle Valo * stop_device 55e705c121SKalle Valo * 56e705c121SKalle Valo * 6) Eventually, the free function will be called. 57e705c121SKalle Valo */ 58e705c121SKalle Valo 59e701da0cSLuca Coelho #define IWL_TRANS_FW_DBG_DOMAIN(trans) IWL_FW_INI_DOMAIN_ALWAYS_ON 60e701da0cSLuca Coelho 61e705c121SKalle Valo #define FH_RSCSR_FRAME_SIZE_MSK 0x00003FFF /* bits 0-13 */ 62e705c121SKalle Valo #define FH_RSCSR_FRAME_INVALID 0x55550000 63e705c121SKalle Valo #define FH_RSCSR_FRAME_ALIGN 0x40 64fbe41127SSara Sharon #define FH_RSCSR_RPA_EN BIT(25) 659d0fc5a5SDavid Spinadel #define FH_RSCSR_RADA_EN BIT(26) 66ab2e696bSSara Sharon #define FH_RSCSR_RXQ_POS 16 67ab2e696bSSara Sharon #define FH_RSCSR_RXQ_MASK 0x3F0000 68e705c121SKalle Valo 69e705c121SKalle Valo struct iwl_rx_packet { 70e705c121SKalle Valo /* 71e705c121SKalle Valo * The first 4 bytes of the RX frame header contain both the RX frame 72e705c121SKalle Valo * size and some flags. 73e705c121SKalle Valo * Bit fields: 74e705c121SKalle Valo * 31: flag flush RB request 75e705c121SKalle Valo * 30: flag ignore TC (terminal counter) request 76e705c121SKalle Valo * 29: flag fast IRQ request 779d0fc5a5SDavid Spinadel * 28-27: Reserved 789d0fc5a5SDavid Spinadel * 26: RADA enabled 79fbe41127SSara Sharon * 25: Offload enabled 80ab2e696bSSara Sharon * 24: RPF enabled 81ab2e696bSSara Sharon * 23: RSS enabled 82ab2e696bSSara Sharon * 22: Checksum enabled 83ab2e696bSSara Sharon * 21-16: RX queue 84ab2e696bSSara Sharon * 15-14: Reserved 85e705c121SKalle Valo * 13-00: RX frame size 86e705c121SKalle Valo */ 87e705c121SKalle Valo __le32 len_n_flags; 88e705c121SKalle Valo struct iwl_cmd_header hdr; 89e705c121SKalle Valo u8 data[]; 90e705c121SKalle Valo } __packed; 91e705c121SKalle Valo 92e705c121SKalle Valo static inline u32 iwl_rx_packet_len(const struct iwl_rx_packet *pkt) 93e705c121SKalle Valo { 94e705c121SKalle Valo return le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; 95e705c121SKalle Valo } 96e705c121SKalle Valo 97e705c121SKalle Valo static inline u32 iwl_rx_packet_payload_len(const struct iwl_rx_packet *pkt) 98e705c121SKalle Valo { 99e705c121SKalle Valo return iwl_rx_packet_len(pkt) - sizeof(pkt->hdr); 100e705c121SKalle Valo } 101e705c121SKalle Valo 102e705c121SKalle Valo /** 103e705c121SKalle Valo * enum CMD_MODE - how to send the host commands ? 104e705c121SKalle Valo * 105e705c121SKalle Valo * @CMD_ASYNC: Return right away and don't wait for the response 106e705c121SKalle Valo * @CMD_WANT_SKB: Not valid with CMD_ASYNC. The caller needs the buffer of 107e705c121SKalle Valo * the response. The caller needs to call iwl_free_resp when done. 108dcbb4746SEmmanuel Grumbach * @CMD_WANT_ASYNC_CALLBACK: the op_mode's async callback function must be 109dcbb4746SEmmanuel Grumbach * called after this command completes. Valid only with CMD_ASYNC. 110708a39aaSHaim Dreyfuss * @CMD_SEND_IN_D3: Allow the command to be sent in D3 mode, relevant to 111708a39aaSHaim Dreyfuss * SUSPEND and RESUME commands. We are in D3 mode when we set 112708a39aaSHaim Dreyfuss * trans->system_pm_mode to IWL_PLAT_PM_MODE_D3. 113e705c121SKalle Valo */ 114e705c121SKalle Valo enum CMD_MODE { 115e705c121SKalle Valo CMD_ASYNC = BIT(0), 116e705c121SKalle Valo CMD_WANT_SKB = BIT(1), 117e705c121SKalle Valo CMD_SEND_IN_RFKILL = BIT(2), 118043fa901SEmmanuel Grumbach CMD_WANT_ASYNC_CALLBACK = BIT(3), 119708a39aaSHaim Dreyfuss CMD_SEND_IN_D3 = BIT(4), 120e705c121SKalle Valo }; 121e705c121SKalle Valo 122e705c121SKalle Valo #define DEF_CMD_PAYLOAD_SIZE 320 123e705c121SKalle Valo 124e705c121SKalle Valo /** 125e705c121SKalle Valo * struct iwl_device_cmd 126e705c121SKalle Valo * 127e705c121SKalle Valo * For allocation of the command and tx queues, this establishes the overall 128e705c121SKalle Valo * size of the largest command we send to uCode, except for commands that 129e705c121SKalle Valo * aren't fully copied and use other TFD space. 130e705c121SKalle Valo */ 131e705c121SKalle Valo struct iwl_device_cmd { 132e705c121SKalle Valo union { 133e705c121SKalle Valo struct { 134e705c121SKalle Valo struct iwl_cmd_header hdr; /* uCode API */ 135e705c121SKalle Valo u8 payload[DEF_CMD_PAYLOAD_SIZE]; 136e705c121SKalle Valo }; 137e705c121SKalle Valo struct { 138e705c121SKalle Valo struct iwl_cmd_header_wide hdr_wide; 139e705c121SKalle Valo u8 payload_wide[DEF_CMD_PAYLOAD_SIZE - 140e705c121SKalle Valo sizeof(struct iwl_cmd_header_wide) + 141e705c121SKalle Valo sizeof(struct iwl_cmd_header)]; 142e705c121SKalle Valo }; 143e705c121SKalle Valo }; 144e705c121SKalle Valo } __packed; 145e705c121SKalle Valo 146a89c72ffSJohannes Berg /** 147a89c72ffSJohannes Berg * struct iwl_device_tx_cmd - buffer for TX command 148a89c72ffSJohannes Berg * @hdr: the header 149a89c72ffSJohannes Berg * @payload: the payload placeholder 150a89c72ffSJohannes Berg * 151a89c72ffSJohannes Berg * The actual structure is sized dynamically according to need. 152a89c72ffSJohannes Berg */ 153a89c72ffSJohannes Berg struct iwl_device_tx_cmd { 154a89c72ffSJohannes Berg struct iwl_cmd_header hdr; 155a89c72ffSJohannes Berg u8 payload[]; 156a89c72ffSJohannes Berg } __packed; 157a89c72ffSJohannes Berg 158e705c121SKalle Valo #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_device_cmd)) 159e705c121SKalle Valo 160e705c121SKalle Valo /* 161e705c121SKalle Valo * number of transfer buffers (fragments) per transmit frame descriptor; 162e705c121SKalle Valo * this is just the driver's idea, the hardware supports 20 163e705c121SKalle Valo */ 164e705c121SKalle Valo #define IWL_MAX_CMD_TBS_PER_TFD 2 165e705c121SKalle Valo 166885375d0SMordechay Goodstein /* We need 2 entries for the TX command and header, and another one might 167885375d0SMordechay Goodstein * be needed for potential data in the SKB's head. The remaining ones can 168885375d0SMordechay Goodstein * be used for frags. 169885375d0SMordechay Goodstein */ 170885375d0SMordechay Goodstein #define IWL_TRANS_MAX_FRAGS(trans) ((trans)->txqs.tfd.max_tbs - 3) 171885375d0SMordechay Goodstein 172e705c121SKalle Valo /** 173b8aed81cSJohannes Berg * enum iwl_hcmd_dataflag - flag for each one of the chunks of the command 174e705c121SKalle Valo * 175e705c121SKalle Valo * @IWL_HCMD_DFL_NOCOPY: By default, the command is copied to the host command's 176e705c121SKalle Valo * ring. The transport layer doesn't map the command's buffer to DMA, but 177e705c121SKalle Valo * rather copies it to a previously allocated DMA buffer. This flag tells 178e705c121SKalle Valo * the transport layer not to copy the command, but to map the existing 179e705c121SKalle Valo * buffer (that is passed in) instead. This saves the memcpy and allows 180e705c121SKalle Valo * commands that are bigger than the fixed buffer to be submitted. 181e705c121SKalle Valo * Note that a TFD entry after a NOCOPY one cannot be a normal copied one. 182e705c121SKalle Valo * @IWL_HCMD_DFL_DUP: Only valid without NOCOPY, duplicate the memory for this 183e705c121SKalle Valo * chunk internally and free it again after the command completes. This 184e705c121SKalle Valo * can (currently) be used only once per command. 185e705c121SKalle Valo * Note that a TFD entry after a DUP one cannot be a normal copied one. 186e705c121SKalle Valo */ 187e705c121SKalle Valo enum iwl_hcmd_dataflag { 188e705c121SKalle Valo IWL_HCMD_DFL_NOCOPY = BIT(0), 189e705c121SKalle Valo IWL_HCMD_DFL_DUP = BIT(1), 190e705c121SKalle Valo }; 191e705c121SKalle Valo 19222463857SShahar S Matityahu enum iwl_error_event_table_status { 19322463857SShahar S Matityahu IWL_ERROR_EVENT_TABLE_LMAC1 = BIT(0), 19422463857SShahar S Matityahu IWL_ERROR_EVENT_TABLE_LMAC2 = BIT(1), 19522463857SShahar S Matityahu IWL_ERROR_EVENT_TABLE_UMAC = BIT(2), 19657417e1bSJohannes Berg IWL_ERROR_EVENT_TABLE_TCM1 = BIT(3), 19757417e1bSJohannes Berg IWL_ERROR_EVENT_TABLE_TCM2 = BIT(4), 1984cd177b4SJohannes Berg IWL_ERROR_EVENT_TABLE_RCM1 = BIT(5), 1994cd177b4SJohannes Berg IWL_ERROR_EVENT_TABLE_RCM2 = BIT(6), 20022463857SShahar S Matityahu }; 20122463857SShahar S Matityahu 202e705c121SKalle Valo /** 203e705c121SKalle Valo * struct iwl_host_cmd - Host command to the uCode 204e705c121SKalle Valo * 205e705c121SKalle Valo * @data: array of chunks that composes the data of the host command 206e705c121SKalle Valo * @resp_pkt: response packet, if %CMD_WANT_SKB was set 207e705c121SKalle Valo * @_rx_page_order: (internally used to free response packet) 208e705c121SKalle Valo * @_rx_page_addr: (internally used to free response packet) 209e705c121SKalle Valo * @flags: can be CMD_* 210e705c121SKalle Valo * @len: array of the lengths of the chunks in data 211e705c121SKalle Valo * @dataflags: IWL_HCMD_DFL_* 212e705c121SKalle Valo * @id: command id of the host command, for wide commands encoding the 213e705c121SKalle Valo * version and group as well 214e705c121SKalle Valo */ 215e705c121SKalle Valo struct iwl_host_cmd { 216e705c121SKalle Valo const void *data[IWL_MAX_CMD_TBS_PER_TFD]; 217e705c121SKalle Valo struct iwl_rx_packet *resp_pkt; 218e705c121SKalle Valo unsigned long _rx_page_addr; 219e705c121SKalle Valo u32 _rx_page_order; 220e705c121SKalle Valo 221e705c121SKalle Valo u32 flags; 222e705c121SKalle Valo u32 id; 223e705c121SKalle Valo u16 len[IWL_MAX_CMD_TBS_PER_TFD]; 224e705c121SKalle Valo u8 dataflags[IWL_MAX_CMD_TBS_PER_TFD]; 225e705c121SKalle Valo }; 226e705c121SKalle Valo 227e705c121SKalle Valo static inline void iwl_free_resp(struct iwl_host_cmd *cmd) 228e705c121SKalle Valo { 229e705c121SKalle Valo free_pages(cmd->_rx_page_addr, cmd->_rx_page_order); 230e705c121SKalle Valo } 231e705c121SKalle Valo 232e705c121SKalle Valo struct iwl_rx_cmd_buffer { 233e705c121SKalle Valo struct page *_page; 234e705c121SKalle Valo int _offset; 235e705c121SKalle Valo bool _page_stolen; 236e705c121SKalle Valo u32 _rx_page_order; 237e705c121SKalle Valo unsigned int truesize; 238e705c121SKalle Valo }; 239e705c121SKalle Valo 240e705c121SKalle Valo static inline void *rxb_addr(struct iwl_rx_cmd_buffer *r) 241e705c121SKalle Valo { 242e705c121SKalle Valo return (void *)((unsigned long)page_address(r->_page) + r->_offset); 243e705c121SKalle Valo } 244e705c121SKalle Valo 245e705c121SKalle Valo static inline int rxb_offset(struct iwl_rx_cmd_buffer *r) 246e705c121SKalle Valo { 247e705c121SKalle Valo return r->_offset; 248e705c121SKalle Valo } 249e705c121SKalle Valo 250e705c121SKalle Valo static inline struct page *rxb_steal_page(struct iwl_rx_cmd_buffer *r) 251e705c121SKalle Valo { 252e705c121SKalle Valo r->_page_stolen = true; 253e705c121SKalle Valo get_page(r->_page); 254e705c121SKalle Valo return r->_page; 255e705c121SKalle Valo } 256e705c121SKalle Valo 257e705c121SKalle Valo static inline void iwl_free_rxb(struct iwl_rx_cmd_buffer *r) 258e705c121SKalle Valo { 259e705c121SKalle Valo __free_pages(r->_page, r->_rx_page_order); 260e705c121SKalle Valo } 261e705c121SKalle Valo 262e705c121SKalle Valo #define MAX_NO_RECLAIM_CMDS 6 263e705c121SKalle Valo 264e705c121SKalle Valo #define IWL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo)))) 265e705c121SKalle Valo 266e705c121SKalle Valo /* 267e705c121SKalle Valo * Maximum number of HW queues the transport layer 268e705c121SKalle Valo * currently supports 269e705c121SKalle Valo */ 270e705c121SKalle Valo #define IWL_MAX_HW_QUEUES 32 271e982bc2cSSara Sharon #define IWL_MAX_TVQM_QUEUES 512 272e982bc2cSSara Sharon 273e705c121SKalle Valo #define IWL_MAX_TID_COUNT 8 274c65f4e03SSara Sharon #define IWL_MGMT_TID 15 275e705c121SKalle Valo #define IWL_FRAME_LIMIT 64 276e705c121SKalle Valo #define IWL_MAX_RX_HW_QUEUES 16 2770cd38f4dSMordechay Goodstein #define IWL_9000_MAX_RX_HW_QUEUES 6 278e705c121SKalle Valo 279e705c121SKalle Valo /** 280e705c121SKalle Valo * enum iwl_wowlan_status - WoWLAN image/device status 281e705c121SKalle Valo * @IWL_D3_STATUS_ALIVE: firmware is still running after resume 282e705c121SKalle Valo * @IWL_D3_STATUS_RESET: device was reset while suspended 283e705c121SKalle Valo */ 284e705c121SKalle Valo enum iwl_d3_status { 285e705c121SKalle Valo IWL_D3_STATUS_ALIVE, 286e705c121SKalle Valo IWL_D3_STATUS_RESET, 287e705c121SKalle Valo }; 288e705c121SKalle Valo 289e705c121SKalle Valo /** 290e705c121SKalle Valo * enum iwl_trans_status: transport status flags 291e705c121SKalle Valo * @STATUS_SYNC_HCMD_ACTIVE: a SYNC command is being processed 292e705c121SKalle Valo * @STATUS_DEVICE_ENABLED: APM is enabled 293e705c121SKalle Valo * @STATUS_TPOWER_PMI: the device might be asleep (need to wake it up) 294e705c121SKalle Valo * @STATUS_INT_ENABLED: interrupts are enabled 295326477e4SJohannes Berg * @STATUS_RFKILL_HW: the actual HW state of the RF-kill switch 296326477e4SJohannes Berg * @STATUS_RFKILL_OPMODE: RF-kill state reported to opmode 297e705c121SKalle Valo * @STATUS_FW_ERROR: the fw is in error state 298e705c121SKalle Valo * @STATUS_TRANS_GOING_IDLE: shutting down the trans, only special commands 299e705c121SKalle Valo * are sent 300e705c121SKalle Valo * @STATUS_TRANS_IDLE: the trans is idle - general commands are not to be sent 301e705c121SKalle Valo * @STATUS_TRANS_DEAD: trans is dead - avoid any read/write operation 3024b992db6SJohannes Berg * @STATUS_SUPPRESS_CMD_ERROR_ONCE: suppress "FW error in SYNC CMD" once, 3034b992db6SJohannes Berg * e.g. for testing 304e705c121SKalle Valo */ 305e705c121SKalle Valo enum iwl_trans_status { 306e705c121SKalle Valo STATUS_SYNC_HCMD_ACTIVE, 307e705c121SKalle Valo STATUS_DEVICE_ENABLED, 308e705c121SKalle Valo STATUS_TPOWER_PMI, 309e705c121SKalle Valo STATUS_INT_ENABLED, 310326477e4SJohannes Berg STATUS_RFKILL_HW, 311326477e4SJohannes Berg STATUS_RFKILL_OPMODE, 312e705c121SKalle Valo STATUS_FW_ERROR, 313e705c121SKalle Valo STATUS_TRANS_GOING_IDLE, 314e705c121SKalle Valo STATUS_TRANS_IDLE, 315e705c121SKalle Valo STATUS_TRANS_DEAD, 3164b992db6SJohannes Berg STATUS_SUPPRESS_CMD_ERROR_ONCE, 317e705c121SKalle Valo }; 318e705c121SKalle Valo 3196c4fbcbcSEmmanuel Grumbach static inline int 3206c4fbcbcSEmmanuel Grumbach iwl_trans_get_rb_size_order(enum iwl_amsdu_size rb_size) 3216c4fbcbcSEmmanuel Grumbach { 3226c4fbcbcSEmmanuel Grumbach switch (rb_size) { 3231a4968d1SGolan Ben Ami case IWL_AMSDU_2K: 3241a4968d1SGolan Ben Ami return get_order(2 * 1024); 3256c4fbcbcSEmmanuel Grumbach case IWL_AMSDU_4K: 3266c4fbcbcSEmmanuel Grumbach return get_order(4 * 1024); 3276c4fbcbcSEmmanuel Grumbach case IWL_AMSDU_8K: 3286c4fbcbcSEmmanuel Grumbach return get_order(8 * 1024); 3296c4fbcbcSEmmanuel Grumbach case IWL_AMSDU_12K: 3303fa965c2SJohannes Berg return get_order(16 * 1024); 3316c4fbcbcSEmmanuel Grumbach default: 3326c4fbcbcSEmmanuel Grumbach WARN_ON(1); 3336c4fbcbcSEmmanuel Grumbach return -1; 3346c4fbcbcSEmmanuel Grumbach } 3356c4fbcbcSEmmanuel Grumbach } 3366c4fbcbcSEmmanuel Grumbach 33780084e35SJohannes Berg static inline int 33880084e35SJohannes Berg iwl_trans_get_rb_size(enum iwl_amsdu_size rb_size) 33980084e35SJohannes Berg { 34080084e35SJohannes Berg switch (rb_size) { 34180084e35SJohannes Berg case IWL_AMSDU_2K: 34280084e35SJohannes Berg return 2 * 1024; 34380084e35SJohannes Berg case IWL_AMSDU_4K: 34480084e35SJohannes Berg return 4 * 1024; 34580084e35SJohannes Berg case IWL_AMSDU_8K: 34680084e35SJohannes Berg return 8 * 1024; 34780084e35SJohannes Berg case IWL_AMSDU_12K: 3483fa965c2SJohannes Berg return 16 * 1024; 34980084e35SJohannes Berg default: 35080084e35SJohannes Berg WARN_ON(1); 35180084e35SJohannes Berg return 0; 35280084e35SJohannes Berg } 35380084e35SJohannes Berg } 35480084e35SJohannes Berg 35539bdb17eSSharon Dvir struct iwl_hcmd_names { 35639bdb17eSSharon Dvir u8 cmd_id; 35739bdb17eSSharon Dvir const char *const cmd_name; 35839bdb17eSSharon Dvir }; 35939bdb17eSSharon Dvir 36039bdb17eSSharon Dvir #define HCMD_NAME(x) \ 36139bdb17eSSharon Dvir { .cmd_id = x, .cmd_name = #x } 36239bdb17eSSharon Dvir 36339bdb17eSSharon Dvir struct iwl_hcmd_arr { 36439bdb17eSSharon Dvir const struct iwl_hcmd_names *arr; 36539bdb17eSSharon Dvir int size; 36639bdb17eSSharon Dvir }; 36739bdb17eSSharon Dvir 36839bdb17eSSharon Dvir #define HCMD_ARR(x) \ 36939bdb17eSSharon Dvir { .arr = x, .size = ARRAY_SIZE(x) } 37039bdb17eSSharon Dvir 371e705c121SKalle Valo /** 372fdb70083SJohannes Berg * struct iwl_dump_sanitize_ops - dump sanitization operations 373fdb70083SJohannes Berg * @frob_txf: Scrub the TX FIFO data 374fdb70083SJohannes Berg * @frob_hcmd: Scrub a host command, the %hcmd pointer is to the header 375fdb70083SJohannes Berg * but that might be short or long (&struct iwl_cmd_header or 376fdb70083SJohannes Berg * &struct iwl_cmd_header_wide) 377fdb70083SJohannes Berg * @frob_mem: Scrub memory data 378fdb70083SJohannes Berg */ 379fdb70083SJohannes Berg struct iwl_dump_sanitize_ops { 380fdb70083SJohannes Berg void (*frob_txf)(void *ctx, void *buf, size_t buflen); 381fdb70083SJohannes Berg void (*frob_hcmd)(void *ctx, void *hcmd, size_t buflen); 382fdb70083SJohannes Berg void (*frob_mem)(void *ctx, u32 mem_addr, void *mem, size_t buflen); 383fdb70083SJohannes Berg }; 384fdb70083SJohannes Berg 385fdb70083SJohannes Berg /** 386e705c121SKalle Valo * struct iwl_trans_config - transport configuration 387e705c121SKalle Valo * 388e705c121SKalle Valo * @op_mode: pointer to the upper layer. 389e705c121SKalle Valo * @cmd_queue: the index of the command queue. 390e705c121SKalle Valo * Must be set before start_fw. 391e705c121SKalle Valo * @cmd_fifo: the fifo for host commands 392e705c121SKalle Valo * @cmd_q_wdg_timeout: the timeout of the watchdog timer for the command queue. 393e705c121SKalle Valo * @no_reclaim_cmds: Some devices erroneously don't set the 394e705c121SKalle Valo * SEQ_RX_FRAME bit on some notifications, this is the 395e705c121SKalle Valo * list of such notifications to filter. Max length is 396e705c121SKalle Valo * %MAX_NO_RECLAIM_CMDS. 397e705c121SKalle Valo * @n_no_reclaim_cmds: # of commands in list 3986c4fbcbcSEmmanuel Grumbach * @rx_buf_size: RX buffer size needed for A-MSDUs 399e705c121SKalle Valo * if unset 4k will be the RX buffer size 400e705c121SKalle Valo * @bc_table_dword: set to true if the BC table expects the byte count to be 401e705c121SKalle Valo * in DWORD (as opposed to bytes) 402e705c121SKalle Valo * @scd_set_active: should the transport configure the SCD for HCMD queue 40339bdb17eSSharon Dvir * @command_groups: array of command groups, each member is an array of the 40439bdb17eSSharon Dvir * commands in the group; for debugging only 40539bdb17eSSharon Dvir * @command_groups_size: number of command groups, to avoid illegal access 40621cb3222SJohannes Berg * @cb_data_offs: offset inside skb->cb to store transport data at, must have 40721cb3222SJohannes Berg * space for at least two pointers 408906d4eb8SJohannes Berg * @fw_reset_handshake: firmware supports reset flow handshake 409227f2597SJohannes Berg * @queue_alloc_cmd_ver: queue allocation command version, set to 0 410227f2597SJohannes Berg * for using the older SCD_QUEUE_CFG, set to the version of 411227f2597SJohannes Berg * SCD_QUEUE_CONFIG_CMD otherwise. 412e705c121SKalle Valo */ 413e705c121SKalle Valo struct iwl_trans_config { 414e705c121SKalle Valo struct iwl_op_mode *op_mode; 415e705c121SKalle Valo 416e705c121SKalle Valo u8 cmd_queue; 417e705c121SKalle Valo u8 cmd_fifo; 418e705c121SKalle Valo unsigned int cmd_q_wdg_timeout; 419e705c121SKalle Valo const u8 *no_reclaim_cmds; 420e705c121SKalle Valo unsigned int n_no_reclaim_cmds; 421e705c121SKalle Valo 4226c4fbcbcSEmmanuel Grumbach enum iwl_amsdu_size rx_buf_size; 423e705c121SKalle Valo bool bc_table_dword; 424e705c121SKalle Valo bool scd_set_active; 42539bdb17eSSharon Dvir const struct iwl_hcmd_arr *command_groups; 42639bdb17eSSharon Dvir int command_groups_size; 427e705c121SKalle Valo 42821cb3222SJohannes Berg u8 cb_data_offs; 429906d4eb8SJohannes Berg bool fw_reset_handshake; 430227f2597SJohannes Berg u8 queue_alloc_cmd_ver; 431e705c121SKalle Valo }; 432e705c121SKalle Valo 433e705c121SKalle Valo struct iwl_trans_dump_data { 434e705c121SKalle Valo u32 len; 435e705c121SKalle Valo u8 data[]; 436e705c121SKalle Valo }; 437e705c121SKalle Valo 438e705c121SKalle Valo struct iwl_trans; 439e705c121SKalle Valo 440e705c121SKalle Valo struct iwl_trans_txq_scd_cfg { 441e705c121SKalle Valo u8 fifo; 4422a2e9d10SLiad Kaufman u8 sta_id; 443e705c121SKalle Valo u8 tid; 444e705c121SKalle Valo bool aggregate; 445e705c121SKalle Valo int frame_limit; 446e705c121SKalle Valo }; 447e705c121SKalle Valo 4486b35ff91SSara Sharon /** 44992536c96SSara Sharon * struct iwl_trans_rxq_dma_data - RX queue DMA data 45092536c96SSara Sharon * @fr_bd_cb: DMA address of free BD cyclic buffer 45192536c96SSara Sharon * @fr_bd_wid: Initial write index of the free BD cyclic buffer 45292536c96SSara Sharon * @urbd_stts_wrptr: DMA address of urbd_stts_wrptr 45392536c96SSara Sharon * @ur_bd_cb: DMA address of used BD cyclic buffer 45492536c96SSara Sharon */ 45592536c96SSara Sharon struct iwl_trans_rxq_dma_data { 45692536c96SSara Sharon u64 fr_bd_cb; 45792536c96SSara Sharon u32 fr_bd_wid; 45892536c96SSara Sharon u64 urbd_stts_wrptr; 45992536c96SSara Sharon u64 ur_bd_cb; 46092536c96SSara Sharon }; 46192536c96SSara Sharon 4625f408503SAlon Giladi /* maximal number of DRAM MAP entries supported by FW */ 4635f408503SAlon Giladi #define IPC_DRAM_MAP_ENTRY_NUM_MAX 64 4645f408503SAlon Giladi 4655f408503SAlon Giladi /** 4665f408503SAlon Giladi * struct iwl_pnvm_image - contains info about the parsed pnvm image 4675f408503SAlon Giladi * @chunks: array of pointers to pnvm payloads and their sizes 4685f408503SAlon Giladi * @n_chunks: the number of the pnvm payloads. 469b99e32cbSAlon Giladi * @version: the version of the loaded PNVM image 4705f408503SAlon Giladi */ 4715f408503SAlon Giladi struct iwl_pnvm_image { 4725f408503SAlon Giladi struct { 4735f408503SAlon Giladi const void *data; 4745f408503SAlon Giladi u32 len; 4755f408503SAlon Giladi } chunks[IPC_DRAM_MAP_ENTRY_NUM_MAX]; 4765f408503SAlon Giladi u32 n_chunks; 477b99e32cbSAlon Giladi u32 version; 4785f408503SAlon Giladi }; 4795f408503SAlon Giladi 48092536c96SSara Sharon /** 481e705c121SKalle Valo * struct iwl_trans_ops - transport specific operations 482e705c121SKalle Valo * 483e705c121SKalle Valo * All the handlers MUST be implemented 484e705c121SKalle Valo * 485bab3cb92SEmmanuel Grumbach * @start_hw: starts the HW. From that point on, the HW can send interrupts. 486bab3cb92SEmmanuel Grumbach * May sleep. 487e705c121SKalle Valo * @op_mode_leave: Turn off the HW RF kill indication if on 488e705c121SKalle Valo * May sleep 489e705c121SKalle Valo * @start_fw: allocates and inits all the resources for the transport 490e705c121SKalle Valo * layer. Also kick a fw image. 491e705c121SKalle Valo * May sleep 492e705c121SKalle Valo * @fw_alive: called when the fw sends alive notification. If the fw provides 493e705c121SKalle Valo * the SCD base address in SRAM, then provide it here, or 0 otherwise. 494e705c121SKalle Valo * May sleep 495e705c121SKalle Valo * @stop_device: stops the whole device (embedded CPU put to reset) and stops 496bab3cb92SEmmanuel Grumbach * the HW. From that point on, the HW will be stopped but will still issue 497bab3cb92SEmmanuel Grumbach * an interrupt if the HW RF kill switch is triggered. 498e705c121SKalle Valo * This callback must do the right thing and not crash even if %start_hw() 499e705c121SKalle Valo * was called but not &start_fw(). May sleep. 500e705c121SKalle Valo * @d3_suspend: put the device into the correct mode for WoWLAN during 501e705c121SKalle Valo * suspend. This is optional, if not implemented WoWLAN will not be 502e705c121SKalle Valo * supported. This callback may sleep. 503e705c121SKalle Valo * @d3_resume: resume the device after WoWLAN, enabling the opmode to 504e705c121SKalle Valo * talk to the WoWLAN image to get its status. This is optional, if not 505e705c121SKalle Valo * implemented WoWLAN will not be supported. This callback may sleep. 506e705c121SKalle Valo * @send_cmd:send a host command. Must return -ERFKILL if RFkill is asserted. 507e705c121SKalle Valo * If RFkill is asserted in the middle of a SYNC host command, it must 508e705c121SKalle Valo * return -ERFKILL straight away. 509e705c121SKalle Valo * May sleep only if CMD_ASYNC is not set 5103f73b8caSEmmanuel Grumbach * @tx: send an skb. The transport relies on the op_mode to zero the 5116eb5e529SEmmanuel Grumbach * the ieee80211_tx_info->driver_data. If the MPDU is an A-MSDU, all 5126eb5e529SEmmanuel Grumbach * the CSUM will be taken care of (TCP CSUM and IP header in case of 5136eb5e529SEmmanuel Grumbach * IPv4). If the MPDU is a single MSDU, the op_mode must compute the IP 5146eb5e529SEmmanuel Grumbach * header if it is IPv4. 515e705c121SKalle Valo * Must be atomic 516e705c121SKalle Valo * @reclaim: free packet until ssn. Returns a list of freed packets. 517e705c121SKalle Valo * Must be atomic 518e705c121SKalle Valo * @txq_enable: setup a queue. To setup an AC queue, use the 519e705c121SKalle Valo * iwl_trans_ac_txq_enable wrapper. fw_alive must have been called before 520e705c121SKalle Valo * this one. The op_mode must not configure the HCMD queue. The scheduler 521e705c121SKalle Valo * configuration may be %NULL, in which case the hardware will not be 522dcfbd67bSEmmanuel Grumbach * configured. If true is returned, the operation mode needs to increment 523dcfbd67bSEmmanuel Grumbach * the sequence number of the packets routed to this queue because of a 524dcfbd67bSEmmanuel Grumbach * hardware scheduler bug. May sleep. 525e705c121SKalle Valo * @txq_disable: de-configure a Tx queue to send AMPDUs 526e705c121SKalle Valo * Must be atomic 52742db09c1SLiad Kaufman * @txq_set_shared_mode: change Tx queue shared/unshared marking 528d6d517b7SSara Sharon * @wait_tx_queues_empty: wait until tx queues are empty. May sleep. 529d6d517b7SSara Sharon * @wait_txq_empty: wait until specific tx queue is empty. May sleep. 530e705c121SKalle Valo * @freeze_txq_timer: prevents the timer of the queue from firing until the 531e705c121SKalle Valo * queue is set to awake. Must be atomic. 5320cd58eaaSEmmanuel Grumbach * @block_txq_ptrs: stop updating the write pointers of the Tx queues. Note 5330cd58eaaSEmmanuel Grumbach * that the transport needs to refcount the calls since this function 5340cd58eaaSEmmanuel Grumbach * will be called several times with block = true, and then the queues 5350cd58eaaSEmmanuel Grumbach * need to be unblocked only after the same number of calls with 5360cd58eaaSEmmanuel Grumbach * block = false. 537e705c121SKalle Valo * @write8: write a u8 to a register at offset ofs from the BAR 538e705c121SKalle Valo * @write32: write a u32 to a register at offset ofs from the BAR 539e705c121SKalle Valo * @read32: read a u32 register at offset ofs from the BAR 540e705c121SKalle Valo * @read_prph: read a DWORD from a periphery register 541e705c121SKalle Valo * @write_prph: write a DWORD to a periphery register 542e705c121SKalle Valo * @read_mem: read device's SRAM in DWORD 543e705c121SKalle Valo * @write_mem: write device's SRAM in DWORD. If %buf is %NULL, then the memory 544e705c121SKalle Valo * will be zeroed. 545f696a7eeSLuca Coelho * @read_config32: read a u32 value from the device's config space at 546f696a7eeSLuca Coelho * the given offset. 547e705c121SKalle Valo * @configure: configure parameters required by the transport layer from 548e705c121SKalle Valo * the op_mode. May be called several times before start_fw, can't be 549e705c121SKalle Valo * called after that. 550e705c121SKalle Valo * @set_pmi: set the power pmi state 551e705c121SKalle Valo * @grab_nic_access: wake the NIC to be able to access non-HBUS regs. 552e705c121SKalle Valo * Sleeping is not allowed between grab_nic_access and 553e705c121SKalle Valo * release_nic_access. 554e705c121SKalle Valo * @release_nic_access: let the NIC go to sleep. The "flags" parameter 555e705c121SKalle Valo * must be the same one that was sent before to the grab_nic_access. 556e705c121SKalle Valo * @set_bits_mask - set SRAM register according to value and mask. 557e705c121SKalle Valo * @dump_data: return a vmalloc'ed buffer with debug data, maybe containing last 558e705c121SKalle Valo * TX'ed commands and similar. The buffer will be vfree'd by the caller. 559e705c121SKalle Valo * Note that the transport must fill in the proper file headers. 560f7805b33SLior Cohen * @debugfs_cleanup: used in the driver unload flow to make a proper cleanup 561f7805b33SLior Cohen * of the trans debugfs 562194d1f84SAlon Giladi * @load_pnvm: save the pnvm data in DRAM 563a182dfabSLuca Coelho * @set_pnvm: set the pnvm data in the prph scratch buffer, inside the 564a182dfabSLuca Coelho * context info. 565*c738fb61SAlon Giladi * @load_reduce_power: copy reduce power table to the corresponding DRAM memory 566*c738fb61SAlon Giladi * @set_reduce_power: set reduce power table addresses in the sratch buffer 5673161a34dSMordechay Goodstein * @interrupts: disable/enable interrupts to transport 568e705c121SKalle Valo */ 569e705c121SKalle Valo struct iwl_trans_ops { 570e705c121SKalle Valo 571bab3cb92SEmmanuel Grumbach int (*start_hw)(struct iwl_trans *iwl_trans); 572e705c121SKalle Valo void (*op_mode_leave)(struct iwl_trans *iwl_trans); 573e705c121SKalle Valo int (*start_fw)(struct iwl_trans *trans, const struct fw_img *fw, 574e705c121SKalle Valo bool run_in_rfkill); 575e705c121SKalle Valo void (*fw_alive)(struct iwl_trans *trans, u32 scd_addr); 576bab3cb92SEmmanuel Grumbach void (*stop_device)(struct iwl_trans *trans); 577e705c121SKalle Valo 578e5f3f215SHaim Dreyfuss int (*d3_suspend)(struct iwl_trans *trans, bool test, bool reset); 579e705c121SKalle Valo int (*d3_resume)(struct iwl_trans *trans, enum iwl_d3_status *status, 58023ae6128SMatti Gottlieb bool test, bool reset); 581e705c121SKalle Valo 582e705c121SKalle Valo int (*send_cmd)(struct iwl_trans *trans, struct iwl_host_cmd *cmd); 583e705c121SKalle Valo 584e705c121SKalle Valo int (*tx)(struct iwl_trans *trans, struct sk_buff *skb, 585a89c72ffSJohannes Berg struct iwl_device_tx_cmd *dev_cmd, int queue); 586e705c121SKalle Valo void (*reclaim)(struct iwl_trans *trans, int queue, int ssn, 587e705c121SKalle Valo struct sk_buff_head *skbs); 588e705c121SKalle Valo 589ba7136f3SAlex Malamud void (*set_q_ptrs)(struct iwl_trans *trans, int queue, int ptr); 590ba7136f3SAlex Malamud 591dcfbd67bSEmmanuel Grumbach bool (*txq_enable)(struct iwl_trans *trans, int queue, u16 ssn, 592e705c121SKalle Valo const struct iwl_trans_txq_scd_cfg *cfg, 593e705c121SKalle Valo unsigned int queue_wdg_timeout); 594e705c121SKalle Valo void (*txq_disable)(struct iwl_trans *trans, int queue, 595e705c121SKalle Valo bool configure_scd); 5962f7a3863SLuca Coelho /* 22000 functions */ 597227f2597SJohannes Berg int (*txq_alloc)(struct iwl_trans *trans, u32 flags, 598227f2597SJohannes Berg u32 sta_mask, u8 tid, 59985b17a33SJohannes Berg int size, unsigned int queue_wdg_timeout); 6006b35ff91SSara Sharon void (*txq_free)(struct iwl_trans *trans, int queue); 60192536c96SSara Sharon int (*rxq_dma_data)(struct iwl_trans *trans, int queue, 60292536c96SSara Sharon struct iwl_trans_rxq_dma_data *data); 603e705c121SKalle Valo 60442db09c1SLiad Kaufman void (*txq_set_shared_mode)(struct iwl_trans *trans, u32 txq_id, 60542db09c1SLiad Kaufman bool shared); 60642db09c1SLiad Kaufman 607a1a57877SSara Sharon int (*wait_tx_queues_empty)(struct iwl_trans *trans, u32 txq_bm); 608d6d517b7SSara Sharon int (*wait_txq_empty)(struct iwl_trans *trans, int queue); 609e705c121SKalle Valo void (*freeze_txq_timer)(struct iwl_trans *trans, unsigned long txqs, 610e705c121SKalle Valo bool freeze); 6110cd58eaaSEmmanuel Grumbach void (*block_txq_ptrs)(struct iwl_trans *trans, bool block); 612e705c121SKalle Valo 613e705c121SKalle Valo void (*write8)(struct iwl_trans *trans, u32 ofs, u8 val); 614e705c121SKalle Valo void (*write32)(struct iwl_trans *trans, u32 ofs, u32 val); 615e705c121SKalle Valo u32 (*read32)(struct iwl_trans *trans, u32 ofs); 616e705c121SKalle Valo u32 (*read_prph)(struct iwl_trans *trans, u32 ofs); 617e705c121SKalle Valo void (*write_prph)(struct iwl_trans *trans, u32 ofs, u32 val); 618e705c121SKalle Valo int (*read_mem)(struct iwl_trans *trans, u32 addr, 619e705c121SKalle Valo void *buf, int dwords); 620e705c121SKalle Valo int (*write_mem)(struct iwl_trans *trans, u32 addr, 621e705c121SKalle Valo const void *buf, int dwords); 622f696a7eeSLuca Coelho int (*read_config32)(struct iwl_trans *trans, u32 ofs, u32 *val); 623e705c121SKalle Valo void (*configure)(struct iwl_trans *trans, 624e705c121SKalle Valo const struct iwl_trans_config *trans_cfg); 625e705c121SKalle Valo void (*set_pmi)(struct iwl_trans *trans, bool state); 62615bf5ac6SJohannes Berg int (*sw_reset)(struct iwl_trans *trans, bool retake_ownership); 6271ed08f6fSJohannes Berg bool (*grab_nic_access)(struct iwl_trans *trans); 6281ed08f6fSJohannes Berg void (*release_nic_access)(struct iwl_trans *trans); 629e705c121SKalle Valo void (*set_bits_mask)(struct iwl_trans *trans, u32 reg, u32 mask, 630e705c121SKalle Valo u32 value); 631e705c121SKalle Valo 632e705c121SKalle Valo struct iwl_trans_dump_data *(*dump_data)(struct iwl_trans *trans, 633fdb70083SJohannes Berg u32 dump_mask, 634fdb70083SJohannes Berg const struct iwl_dump_sanitize_ops *sanitize_ops, 635fdb70083SJohannes Berg void *sanitize_ctx); 636f7805b33SLior Cohen void (*debugfs_cleanup)(struct iwl_trans *trans); 637d1967ce6SShahar S Matityahu void (*sync_nmi)(struct iwl_trans *trans); 638194d1f84SAlon Giladi int (*load_pnvm)(struct iwl_trans *trans, 63933182810SAlon Giladi const struct iwl_pnvm_image *pnvm_payloads, 64033182810SAlon Giladi const struct iwl_ucode_capabilities *capa); 64133182810SAlon Giladi void (*set_pnvm)(struct iwl_trans *trans, 64233182810SAlon Giladi const struct iwl_ucode_capabilities *capa); 643*c738fb61SAlon Giladi int (*load_reduce_power)(struct iwl_trans *trans, 644*c738fb61SAlon Giladi const void *data, 645*c738fb61SAlon Giladi u32 len); 646*c738fb61SAlon Giladi void (*set_reduce_power)(struct iwl_trans *trans); 647*c738fb61SAlon Giladi 6483161a34dSMordechay Goodstein void (*interrupts)(struct iwl_trans *trans, bool enable); 649c0941aceSMukesh Sisodiya int (*imr_dma_data)(struct iwl_trans *trans, 650c0941aceSMukesh Sisodiya u32 dst_addr, u64 src_addr, 651c0941aceSMukesh Sisodiya u32 byte_cnt); 652c0941aceSMukesh Sisodiya 653e705c121SKalle Valo }; 654e705c121SKalle Valo 655e705c121SKalle Valo /** 656e705c121SKalle Valo * enum iwl_trans_state - state of the transport layer 657e705c121SKalle Valo * 658b2ed841eSJohannes Berg * @IWL_TRANS_NO_FW: firmware wasn't started yet, or crashed 659b2ed841eSJohannes Berg * @IWL_TRANS_FW_STARTED: FW was started, but not alive yet 660b2ed841eSJohannes Berg * @IWL_TRANS_FW_ALIVE: FW has sent an alive response 661e705c121SKalle Valo */ 662e705c121SKalle Valo enum iwl_trans_state { 663b2ed841eSJohannes Berg IWL_TRANS_NO_FW, 664b2ed841eSJohannes Berg IWL_TRANS_FW_STARTED, 665b2ed841eSJohannes Berg IWL_TRANS_FW_ALIVE, 666e705c121SKalle Valo }; 667e705c121SKalle Valo 668e705c121SKalle Valo /** 669b7282643SLuca Coelho * DOC: Platform power management 670e705c121SKalle Valo * 671b7282643SLuca Coelho * In system-wide power management the entire platform goes into a low 672b7282643SLuca Coelho * power state (e.g. idle or suspend to RAM) at the same time and the 673b7282643SLuca Coelho * device is configured as a wakeup source for the entire platform. 674b7282643SLuca Coelho * This is usually triggered by userspace activity (e.g. the user 675b7282643SLuca Coelho * presses the suspend button or a power management daemon decides to 676b7282643SLuca Coelho * put the platform in low power mode). The device's behavior in this 677b7282643SLuca Coelho * mode is dictated by the wake-on-WLAN configuration. 678b7282643SLuca Coelho * 679b7282643SLuca Coelho * The terms used for the device's behavior are as follows: 680b7282643SLuca Coelho * 681b7282643SLuca Coelho * - D0: the device is fully powered and the host is awake; 682b7282643SLuca Coelho * - D3: the device is in low power mode and only reacts to 683b7282643SLuca Coelho * specific events (e.g. magic-packet received or scan 684b7282643SLuca Coelho * results found); 685b7282643SLuca Coelho * 686b7282643SLuca Coelho * These terms reflect the power modes in the firmware and are not to 687f60e2750SEmmanuel Grumbach * be confused with the physical device power state. 688e705c121SKalle Valo */ 689b7282643SLuca Coelho 690b7282643SLuca Coelho /** 691b7282643SLuca Coelho * enum iwl_plat_pm_mode - platform power management mode 692b7282643SLuca Coelho * 693b7282643SLuca Coelho * This enumeration describes the device's platform power management 694f60e2750SEmmanuel Grumbach * behavior when in system-wide suspend (i.e WoWLAN). 695b7282643SLuca Coelho * 696b7282643SLuca Coelho * @IWL_PLAT_PM_MODE_DISABLED: power management is disabled for this 697f60e2750SEmmanuel Grumbach * device. In system-wide suspend mode, it means that the all 698f60e2750SEmmanuel Grumbach * connections will be closed automatically by mac80211 before 699f60e2750SEmmanuel Grumbach * the platform is suspended. 700b7282643SLuca Coelho * @IWL_PLAT_PM_MODE_D3: the device goes into D3 mode (i.e. WoWLAN). 701b7282643SLuca Coelho */ 702b7282643SLuca Coelho enum iwl_plat_pm_mode { 703b7282643SLuca Coelho IWL_PLAT_PM_MODE_DISABLED, 704b7282643SLuca Coelho IWL_PLAT_PM_MODE_D3, 705e705c121SKalle Valo }; 706e705c121SKalle Valo 707341bd290SShahar S Matityahu /** 708341bd290SShahar S Matityahu * enum iwl_ini_cfg_state 709341bd290SShahar S Matityahu * @IWL_INI_CFG_STATE_NOT_LOADED: no debug cfg was given 710341bd290SShahar S Matityahu * @IWL_INI_CFG_STATE_LOADED: debug cfg was found and loaded 711341bd290SShahar S Matityahu * @IWL_INI_CFG_STATE_CORRUPTED: debug cfg was found and some of the TLVs 712341bd290SShahar S Matityahu * are corrupted. The rest of the debug TLVs will still be used 713341bd290SShahar S Matityahu */ 714341bd290SShahar S Matityahu enum iwl_ini_cfg_state { 715341bd290SShahar S Matityahu IWL_INI_CFG_STATE_NOT_LOADED, 716341bd290SShahar S Matityahu IWL_INI_CFG_STATE_LOADED, 717341bd290SShahar S Matityahu IWL_INI_CFG_STATE_CORRUPTED, 718341bd290SShahar S Matityahu }; 719341bd290SShahar S Matityahu 720b8a7547dSShahar S Matityahu /* Max time to wait for nmi interrupt */ 721b8a7547dSShahar S Matityahu #define IWL_TRANS_NMI_TIMEOUT (HZ / 4) 722b8a7547dSShahar S Matityahu 72388964b2eSSara Sharon /** 72488964b2eSSara Sharon * struct iwl_dram_data 72588964b2eSSara Sharon * @physical: page phy pointer 72688964b2eSSara Sharon * @block: pointer to the allocated block/page 72788964b2eSSara Sharon * @size: size of the block/page 72888964b2eSSara Sharon */ 72988964b2eSSara Sharon struct iwl_dram_data { 73088964b2eSSara Sharon dma_addr_t physical; 73188964b2eSSara Sharon void *block; 73288964b2eSSara Sharon int size; 73388964b2eSSara Sharon }; 7344cbb8e50SLuciano Coelho 735e705c121SKalle Valo /** 736593fae3eSShahar S Matityahu * struct iwl_fw_mon - fw monitor per allocation id 737593fae3eSShahar S Matityahu * @num_frags: number of fragments 738593fae3eSShahar S Matityahu * @frags: an array of DRAM buffer fragments 739593fae3eSShahar S Matityahu */ 740593fae3eSShahar S Matityahu struct iwl_fw_mon { 741593fae3eSShahar S Matityahu u32 num_frags; 742593fae3eSShahar S Matityahu struct iwl_dram_data *frags; 743593fae3eSShahar S Matityahu }; 744593fae3eSShahar S Matityahu 745593fae3eSShahar S Matityahu /** 746505a00c0SShahar S Matityahu * struct iwl_self_init_dram - dram data used by self init process 747505a00c0SShahar S Matityahu * @fw: lmac and umac dram data 748505a00c0SShahar S Matityahu * @fw_cnt: total number of items in array 749505a00c0SShahar S Matityahu * @paging: paging dram data 750505a00c0SShahar S Matityahu * @paging_cnt: total number of items in array 751505a00c0SShahar S Matityahu */ 752505a00c0SShahar S Matityahu struct iwl_self_init_dram { 753505a00c0SShahar S Matityahu struct iwl_dram_data *fw; 754505a00c0SShahar S Matityahu int fw_cnt; 755505a00c0SShahar S Matityahu struct iwl_dram_data *paging; 756505a00c0SShahar S Matityahu int paging_cnt; 757505a00c0SShahar S Matityahu }; 758505a00c0SShahar S Matityahu 759505a00c0SShahar S Matityahu /** 760c0941aceSMukesh Sisodiya * struct iwl_imr_data - imr dram data used during debug process 761c0941aceSMukesh Sisodiya * @imr_enable: imr enable status received from fw 762c0941aceSMukesh Sisodiya * @imr_size: imr dram size received from fw 763c0941aceSMukesh Sisodiya * @sram_addr: sram address from debug tlv 764c0941aceSMukesh Sisodiya * @sram_size: sram size from debug tlv 765c0941aceSMukesh Sisodiya * @imr2sram_remainbyte`: size remained after each dma transfer 766c0941aceSMukesh Sisodiya * @imr_curr_addr: current dst address used during dma transfer 767c0941aceSMukesh Sisodiya * @imr_base_addr: imr address received from fw 768c0941aceSMukesh Sisodiya */ 769c0941aceSMukesh Sisodiya struct iwl_imr_data { 770c0941aceSMukesh Sisodiya u32 imr_enable; 771c0941aceSMukesh Sisodiya u32 imr_size; 772c0941aceSMukesh Sisodiya u32 sram_addr; 773c0941aceSMukesh Sisodiya u32 sram_size; 774c0941aceSMukesh Sisodiya u32 imr2sram_remainbyte; 775c0941aceSMukesh Sisodiya u64 imr_curr_addr; 776c0941aceSMukesh Sisodiya __le64 imr_base_addr; 777c0941aceSMukesh Sisodiya }; 778c0941aceSMukesh Sisodiya 7795e31b3dfSMukesh Sisodiya #define IWL_TRANS_CURRENT_PC_NAME_MAX_BYTES 32 7805e31b3dfSMukesh Sisodiya 7815e31b3dfSMukesh Sisodiya /** 7825e31b3dfSMukesh Sisodiya * struct iwl_pc_data - program counter details 7835e31b3dfSMukesh Sisodiya * @pc_name: cpu name 7845e31b3dfSMukesh Sisodiya * @pc_address: cpu program counter 7855e31b3dfSMukesh Sisodiya */ 7865e31b3dfSMukesh Sisodiya struct iwl_pc_data { 7875e31b3dfSMukesh Sisodiya u8 pc_name[IWL_TRANS_CURRENT_PC_NAME_MAX_BYTES]; 7885e31b3dfSMukesh Sisodiya u32 pc_address; 7895e31b3dfSMukesh Sisodiya }; 7905e31b3dfSMukesh Sisodiya 791c0941aceSMukesh Sisodiya /** 79291c28b83SShahar S Matityahu * struct iwl_trans_debug - transport debug related data 79391c28b83SShahar S Matityahu * 79491c28b83SShahar S Matityahu * @n_dest_reg: num of reg_ops in %dbg_dest_tlv 79591c28b83SShahar S Matityahu * @rec_on: true iff there is a fw debug recording currently active 79691c28b83SShahar S Matityahu * @dest_tlv: points to the destination TLV for debug 79791c28b83SShahar S Matityahu * @conf_tlv: array of pointers to configuration TLVs for debug 79891c28b83SShahar S Matityahu * @trigger_tlv: array of pointers to triggers TLVs for debug 79991c28b83SShahar S Matityahu * @lmac_error_event_table: addrs of lmacs error tables 80091c28b83SShahar S Matityahu * @umac_error_event_table: addr of umac error table 80157417e1bSJohannes Berg * @tcm_error_event_table: address(es) of TCM error table(s) 8024cd177b4SJohannes Berg * @rcm_error_event_table: address(es) of RCM error table(s) 80391c28b83SShahar S Matityahu * @error_event_table_tlv_status: bitmap that indicates what error table 80491c28b83SShahar S Matityahu * pointers was recevied via TLV. uses enum &iwl_error_event_table_status 805341bd290SShahar S Matityahu * @internal_ini_cfg: internal debug cfg state. Uses &enum iwl_ini_cfg_state 806341bd290SShahar S Matityahu * @external_ini_cfg: external debug cfg state. Uses &enum iwl_ini_cfg_state 807593fae3eSShahar S Matityahu * @fw_mon_cfg: debug buffer allocation configuration 808593fae3eSShahar S Matityahu * @fw_mon_ini: DRAM buffer fragments per allocation id 80969f0e505SShahar S Matityahu * @fw_mon: DRAM buffer for firmware monitor 81091c28b83SShahar S Matityahu * @hw_error: equals true if hw error interrupt was received from the FW 811029c25f3SShahar S Matityahu * @ini_dest: debug monitor destination uses &enum iwl_fw_ini_buffer_location 8123b589d56SShahar S Matityahu * @active_regions: active regions 813677d25b2SShahar S Matityahu * @debug_info_tlv_list: list of debug info TLVs 814a9248de4SShahar S Matityahu * @time_point: array of debug time points 81560e8abd9SShahar S Matityahu * @periodic_trig_list: periodic triggers list 816f21baf24SMukesh Sisodiya * @domains_bitmap: bitmap of active domains other than &IWL_FW_INI_DOMAIN_ALWAYS_ON 817f21baf24SMukesh Sisodiya * @ucode_preset: preset based on ucode 81851fa8c02SMukesh Sisodiya * @dump_file_name_ext: dump file name extension 81951fa8c02SMukesh Sisodiya * @dump_file_name_ext_valid: dump file name extension if valid or not 8205e31b3dfSMukesh Sisodiya * @num_pc: number of program counter for cpu 8215e31b3dfSMukesh Sisodiya * @pc_data: details of the program counter 82291c28b83SShahar S Matityahu */ 82391c28b83SShahar S Matityahu struct iwl_trans_debug { 82491c28b83SShahar S Matityahu u8 n_dest_reg; 82591c28b83SShahar S Matityahu bool rec_on; 82691c28b83SShahar S Matityahu 82791c28b83SShahar S Matityahu const struct iwl_fw_dbg_dest_tlv_v1 *dest_tlv; 82891c28b83SShahar S Matityahu const struct iwl_fw_dbg_conf_tlv *conf_tlv[FW_DBG_CONF_MAX]; 82991c28b83SShahar S Matityahu struct iwl_fw_dbg_trigger_tlv * const *trigger_tlv; 83091c28b83SShahar S Matityahu 83191c28b83SShahar S Matityahu u32 lmac_error_event_table[2]; 83291c28b83SShahar S Matityahu u32 umac_error_event_table; 83357417e1bSJohannes Berg u32 tcm_error_event_table[2]; 8344cd177b4SJohannes Berg u32 rcm_error_event_table[2]; 83591c28b83SShahar S Matityahu unsigned int error_event_table_tlv_status; 83691c28b83SShahar S Matityahu 837341bd290SShahar S Matityahu enum iwl_ini_cfg_state internal_ini_cfg; 838341bd290SShahar S Matityahu enum iwl_ini_cfg_state external_ini_cfg; 83991c28b83SShahar S Matityahu 840593fae3eSShahar S Matityahu struct iwl_fw_ini_allocation_tlv fw_mon_cfg[IWL_FW_INI_ALLOCATION_NUM]; 841593fae3eSShahar S Matityahu struct iwl_fw_mon fw_mon_ini[IWL_FW_INI_ALLOCATION_NUM]; 842593fae3eSShahar S Matityahu 84369f0e505SShahar S Matityahu struct iwl_dram_data fw_mon; 84491c28b83SShahar S Matityahu 84591c28b83SShahar S Matityahu bool hw_error; 846029c25f3SShahar S Matityahu enum iwl_fw_ini_buffer_location ini_dest; 8473b589d56SShahar S Matityahu 848beb44c0cSMordechay Goodstein u64 unsupported_region_msk; 8493b589d56SShahar S Matityahu struct iwl_ucode_tlv *active_regions[IWL_FW_INI_MAX_REGION_ID]; 850677d25b2SShahar S Matityahu struct list_head debug_info_tlv_list; 851a9248de4SShahar S Matityahu struct iwl_dbg_tlv_time_point_data 852a9248de4SShahar S Matityahu time_point[IWL_FW_INI_TIME_POINT_NUM]; 85360e8abd9SShahar S Matityahu struct list_head periodic_trig_list; 854cf29c5b6SShahar S Matityahu 855cf29c5b6SShahar S Matityahu u32 domains_bitmap; 856f21baf24SMukesh Sisodiya u32 ucode_preset; 857ddb6b76bSMukesh Sisodiya bool restart_required; 858ddb6b76bSMukesh Sisodiya u32 last_tp_resetfw; 859c0941aceSMukesh Sisodiya struct iwl_imr_data imr_data; 86051fa8c02SMukesh Sisodiya u8 dump_file_name_ext[IWL_FW_INI_MAX_NAME]; 86151fa8c02SMukesh Sisodiya bool dump_file_name_ext_valid; 8625e31b3dfSMukesh Sisodiya u32 num_pc; 8635e31b3dfSMukesh Sisodiya struct iwl_pc_data *pc_data; 86491c28b83SShahar S Matityahu }; 86591c28b83SShahar S Matityahu 8664807e736SMordechay Goodstein struct iwl_dma_ptr { 8674807e736SMordechay Goodstein dma_addr_t dma; 8684807e736SMordechay Goodstein void *addr; 8694807e736SMordechay Goodstein size_t size; 8704807e736SMordechay Goodstein }; 8714807e736SMordechay Goodstein 8724807e736SMordechay Goodstein struct iwl_cmd_meta { 8734807e736SMordechay Goodstein /* only for SYNC commands, iff the reply skb is wanted */ 8744807e736SMordechay Goodstein struct iwl_host_cmd *source; 8754807e736SMordechay Goodstein u32 flags; 8764807e736SMordechay Goodstein u32 tbs; 8774807e736SMordechay Goodstein }; 8784807e736SMordechay Goodstein 8794807e736SMordechay Goodstein /* 8804807e736SMordechay Goodstein * The FH will write back to the first TB only, so we need to copy some data 8814807e736SMordechay Goodstein * into the buffer regardless of whether it should be mapped or not. 8824807e736SMordechay Goodstein * This indicates how big the first TB must be to include the scratch buffer 8834807e736SMordechay Goodstein * and the assigned PN. 8844807e736SMordechay Goodstein * Since PN location is 8 bytes at offset 12, it's 20 now. 8854807e736SMordechay Goodstein * If we make it bigger then allocations will be bigger and copy slower, so 8864807e736SMordechay Goodstein * that's probably not useful. 8874807e736SMordechay Goodstein */ 8884807e736SMordechay Goodstein #define IWL_FIRST_TB_SIZE 20 8894807e736SMordechay Goodstein #define IWL_FIRST_TB_SIZE_ALIGN ALIGN(IWL_FIRST_TB_SIZE, 64) 8904807e736SMordechay Goodstein 8914807e736SMordechay Goodstein struct iwl_pcie_txq_entry { 8924807e736SMordechay Goodstein void *cmd; 8934807e736SMordechay Goodstein struct sk_buff *skb; 8944807e736SMordechay Goodstein /* buffer to free after command completes */ 8954807e736SMordechay Goodstein const void *free_buf; 8964807e736SMordechay Goodstein struct iwl_cmd_meta meta; 8974807e736SMordechay Goodstein }; 8984807e736SMordechay Goodstein 8994807e736SMordechay Goodstein struct iwl_pcie_first_tb_buf { 9004807e736SMordechay Goodstein u8 buf[IWL_FIRST_TB_SIZE_ALIGN]; 9014807e736SMordechay Goodstein }; 9024807e736SMordechay Goodstein 9034807e736SMordechay Goodstein /** 9044807e736SMordechay Goodstein * struct iwl_txq - Tx Queue for DMA 9054807e736SMordechay Goodstein * @q: generic Rx/Tx queue descriptor 9064807e736SMordechay Goodstein * @tfds: transmit frame descriptors (DMA memory) 9074807e736SMordechay Goodstein * @first_tb_bufs: start of command headers, including scratch buffers, for 9084807e736SMordechay Goodstein * the writeback -- this is DMA memory and an array holding one buffer 9094807e736SMordechay Goodstein * for each command on the queue 9104807e736SMordechay Goodstein * @first_tb_dma: DMA address for the first_tb_bufs start 9114807e736SMordechay Goodstein * @entries: transmit entries (driver state) 9124807e736SMordechay Goodstein * @lock: queue lock 9134807e736SMordechay Goodstein * @stuck_timer: timer that fires if queue gets stuck 9144807e736SMordechay Goodstein * @trans: pointer back to transport (for timer) 9154807e736SMordechay Goodstein * @need_update: indicates need to update read/write index 9164807e736SMordechay Goodstein * @ampdu: true if this queue is an ampdu queue for an specific RA/TID 9174807e736SMordechay Goodstein * @wd_timeout: queue watchdog timeout (jiffies) - per queue 9184807e736SMordechay Goodstein * @frozen: tx stuck queue timer is frozen 9194807e736SMordechay Goodstein * @frozen_expiry_remainder: remember how long until the timer fires 9204807e736SMordechay Goodstein * @bc_tbl: byte count table of the queue (relevant only for gen2 transport) 9214807e736SMordechay Goodstein * @write_ptr: 1-st empty entry (index) host_w 9224807e736SMordechay Goodstein * @read_ptr: last used entry (index) host_r 9234807e736SMordechay Goodstein * @dma_addr: physical addr for BD's 9244807e736SMordechay Goodstein * @n_window: safe queue window 9254807e736SMordechay Goodstein * @id: queue id 9264807e736SMordechay Goodstein * @low_mark: low watermark, resume queue if free space more than this 9274807e736SMordechay Goodstein * @high_mark: high watermark, stop queue if free space less than this 9284807e736SMordechay Goodstein * 9294807e736SMordechay Goodstein * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame 9304807e736SMordechay Goodstein * descriptors) and required locking structures. 9314807e736SMordechay Goodstein * 9324807e736SMordechay Goodstein * Note the difference between TFD_QUEUE_SIZE_MAX and n_window: the hardware 9334807e736SMordechay Goodstein * always assumes 256 descriptors, so TFD_QUEUE_SIZE_MAX is always 256 (unless 9344807e736SMordechay Goodstein * there might be HW changes in the future). For the normal TX 9354807e736SMordechay Goodstein * queues, n_window, which is the size of the software queue data 9364807e736SMordechay Goodstein * is also 256; however, for the command queue, n_window is only 9374807e736SMordechay Goodstein * 32 since we don't need so many commands pending. Since the HW 9384807e736SMordechay Goodstein * still uses 256 BDs for DMA though, TFD_QUEUE_SIZE_MAX stays 256. 9394807e736SMordechay Goodstein * This means that we end up with the following: 9404807e736SMordechay Goodstein * HW entries: | 0 | ... | N * 32 | ... | N * 32 + 31 | ... | 255 | 9414807e736SMordechay Goodstein * SW entries: | 0 | ... | 31 | 9424807e736SMordechay Goodstein * where N is a number between 0 and 7. This means that the SW 9434807e736SMordechay Goodstein * data is a window overlayed over the HW queue. 9444807e736SMordechay Goodstein */ 9454807e736SMordechay Goodstein struct iwl_txq { 9464807e736SMordechay Goodstein void *tfds; 9474807e736SMordechay Goodstein struct iwl_pcie_first_tb_buf *first_tb_bufs; 9484807e736SMordechay Goodstein dma_addr_t first_tb_dma; 9494807e736SMordechay Goodstein struct iwl_pcie_txq_entry *entries; 9504807e736SMordechay Goodstein /* lock for syncing changes on the queue */ 9514807e736SMordechay Goodstein spinlock_t lock; 9524807e736SMordechay Goodstein unsigned long frozen_expiry_remainder; 9534807e736SMordechay Goodstein struct timer_list stuck_timer; 9544807e736SMordechay Goodstein struct iwl_trans *trans; 9554807e736SMordechay Goodstein bool need_update; 9564807e736SMordechay Goodstein bool frozen; 9574807e736SMordechay Goodstein bool ampdu; 9584807e736SMordechay Goodstein int block; 9594807e736SMordechay Goodstein unsigned long wd_timeout; 9604807e736SMordechay Goodstein struct sk_buff_head overflow_q; 9614807e736SMordechay Goodstein struct iwl_dma_ptr bc_tbl; 9624807e736SMordechay Goodstein 9634807e736SMordechay Goodstein int write_ptr; 9644807e736SMordechay Goodstein int read_ptr; 9654807e736SMordechay Goodstein dma_addr_t dma_addr; 9664807e736SMordechay Goodstein int n_window; 9674807e736SMordechay Goodstein u32 id; 9684807e736SMordechay Goodstein int low_mark; 9694807e736SMordechay Goodstein int high_mark; 9704807e736SMordechay Goodstein 9714807e736SMordechay Goodstein bool overflow_tx; 9724807e736SMordechay Goodstein }; 9734f4822b7SMordechay Goodstein 9744f4822b7SMordechay Goodstein /** 9754f4822b7SMordechay Goodstein * struct iwl_trans_txqs - transport tx queues data 9764f4822b7SMordechay Goodstein * 9778e3b79f8SMordechay Goodstein * @bc_table_dword: true if the BC table expects DWORD (as opposed to bytes) 97822852fadSMordechay Goodstein * @page_offs: offset from skb->cb to mac header page pointer 97922852fadSMordechay Goodstein * @dev_cmd_offs: offset from skb->cb to iwl_device_tx_cmd pointer 9804f4822b7SMordechay Goodstein * @queue_used - bit mask of used queues 9814f4822b7SMordechay Goodstein * @queue_stopped - bit mask of stopped queues 9820179bfffSMordechay Goodstein * @scd_bc_tbls: gen1 pointer to the byte count table of the scheduler 983227f2597SJohannes Berg * @queue_alloc_cmd_ver: queue allocation command version 9844f4822b7SMordechay Goodstein */ 9854f4822b7SMordechay Goodstein struct iwl_trans_txqs { 9864f4822b7SMordechay Goodstein unsigned long queue_used[BITS_TO_LONGS(IWL_MAX_TVQM_QUEUES)]; 9874f4822b7SMordechay Goodstein unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_TVQM_QUEUES)]; 9884f4822b7SMordechay Goodstein struct iwl_txq *txq[IWL_MAX_TVQM_QUEUES]; 989a26014e2SMordechay Goodstein struct dma_pool *bc_pool; 990a26014e2SMordechay Goodstein size_t bc_tbl_size; 9918e3b79f8SMordechay Goodstein bool bc_table_dword; 99222852fadSMordechay Goodstein u8 page_offs; 99322852fadSMordechay Goodstein u8 dev_cmd_offs; 9944246465eSJohannes Berg struct iwl_tso_hdr_page __percpu *tso_hdr_page; 9958e3b79f8SMordechay Goodstein 9964f4822b7SMordechay Goodstein struct { 9974f4822b7SMordechay Goodstein u8 fifo; 9984f4822b7SMordechay Goodstein u8 q_id; 9994f4822b7SMordechay Goodstein unsigned int wdg_timeout; 10004f4822b7SMordechay Goodstein } cmd; 10014f4822b7SMordechay Goodstein 1002885375d0SMordechay Goodstein struct { 1003885375d0SMordechay Goodstein u8 max_tbs; 1004885375d0SMordechay Goodstein u16 size; 1005885375d0SMordechay Goodstein u8 addr_size; 1006885375d0SMordechay Goodstein } tfd; 10070179bfffSMordechay Goodstein 10080179bfffSMordechay Goodstein struct iwl_dma_ptr scd_bc_tbls; 1009227f2597SJohannes Berg 1010227f2597SJohannes Berg u8 queue_alloc_cmd_ver; 10114f4822b7SMordechay Goodstein }; 10124f4822b7SMordechay Goodstein 101391c28b83SShahar S Matityahu /** 1014e705c121SKalle Valo * struct iwl_trans - transport common data 1015e705c121SKalle Valo * 10166d19a5ebSEmmanuel Grumbach * @csme_own - true if we couldn't get ownership on the device 1017e705c121SKalle Valo * @ops - pointer to iwl_trans_ops 1018e705c121SKalle Valo * @op_mode - pointer to the op_mode 1019286ca8ebSLuca Coelho * @trans_cfg: the trans-specific configuration part 1020e705c121SKalle Valo * @cfg - pointer to the configuration 10216f482e37SSara Sharon * @drv - pointer to iwl_drv 1022e705c121SKalle Valo * @status: a bit-mask of transport status flags 1023e705c121SKalle Valo * @dev - pointer to struct device * that represents the device 1024e705c121SKalle Valo * @max_skb_frags: maximum number of fragments an SKB can have when transmitted. 1025e705c121SKalle Valo * 0 indicates that frag SKBs (NETIF_F_SG) aren't supported. 10261afb0ae4SHaim Dreyfuss * @hw_rf_id a u32 with the device RF ID 10273a27a1a1SMukesh Sisodiya * @hw_crf_id a u32 with the device CRF ID 102872904029SMukesh Sisodiya * @hw_wfpm_id a u32 with the device wfpm ID 1029e705c121SKalle Valo * @hw_id: a u32 with the ID of the device / sub-device. 1030e705c121SKalle Valo * Set during transport allocation. 1031e705c121SKalle Valo * @hw_id_str: a string with info about HW ID. Set during transport allocation. 103255c6d8f8SMike Golant * @hw_rev_step: The mac step of the HW 1033e705c121SKalle Valo * @pm_support: set to true in start_hw if link pm is supported 1034e705c121SKalle Valo * @ltr_enabled: set to true if the LTR is enabled 1035b99e32cbSAlon Giladi * @fail_to_parse_pnvm_image: set to true if pnvm parsing failed 1036b7d96bcaSLuca Coelho * @wide_cmd_header: true when ucode supports wide command header format 103713f028b4SMordechay Goodstein * @wait_command_queue: wait queue for sync commands 1038e705c121SKalle Valo * @num_rx_queues: number of RX queues allocated by the transport; 1039e705c121SKalle Valo * the transport must set this before calling iwl_drv_start() 1040132db31cSGolan Ben-Ami * @iml_len: the length of the image loader 1041132db31cSGolan Ben-Ami * @iml: a pointer to the image loader itself 1042e705c121SKalle Valo * @dev_cmd_pool: pool for Tx cmd allocation - for internal use only. 1043e705c121SKalle Valo * The user should use iwl_trans_{alloc,free}_tx_cmd. 1044e705c121SKalle Valo * @rx_mpdu_cmd: MPDU RX command ID, must be assigned by opmode before 1045e705c121SKalle Valo * starting the firmware, used for tracing 1046e705c121SKalle Valo * @rx_mpdu_cmd_hdr_size: used for tracing, amount of data before the 1047e705c121SKalle Valo * start of the 802.11 header in the @rx_mpdu_cmd 1048e705c121SKalle Valo * @dflt_pwr_limit: default power limit fetched from the platform (ACPI) 1049b7282643SLuca Coelho * @system_pm_mode: the system-wide power management mode in use. 1050b7282643SLuca Coelho * This mode is set dynamically, depending on the WoWLAN values 1051b7282643SLuca Coelho * configured from the userspace at runtime. 10524f4822b7SMordechay Goodstein * @iwl_trans_txqs: transport tx queues data. 105309b4c35dSAyala Barazani * @mbx_addr_0_step: step address data 0 105409b4c35dSAyala Barazani * @mbx_addr_1_step: step address data 1 1055e705c121SKalle Valo */ 1056e705c121SKalle Valo struct iwl_trans { 10576d19a5ebSEmmanuel Grumbach bool csme_own; 1058e705c121SKalle Valo const struct iwl_trans_ops *ops; 1059e705c121SKalle Valo struct iwl_op_mode *op_mode; 1060286ca8ebSLuca Coelho const struct iwl_cfg_trans_params *trans_cfg; 1061e705c121SKalle Valo const struct iwl_cfg *cfg; 10626f482e37SSara Sharon struct iwl_drv *drv; 1063e705c121SKalle Valo enum iwl_trans_state state; 1064e705c121SKalle Valo unsigned long status; 1065e705c121SKalle Valo 1066e705c121SKalle Valo struct device *dev; 1067e705c121SKalle Valo u32 max_skb_frags; 1068e705c121SKalle Valo u32 hw_rev; 106955c6d8f8SMike Golant u32 hw_rev_step; 10701afb0ae4SHaim Dreyfuss u32 hw_rf_id; 10713a27a1a1SMukesh Sisodiya u32 hw_crf_id; 107272904029SMukesh Sisodiya u32 hw_cnv_id; 107372904029SMukesh Sisodiya u32 hw_wfpm_id; 1074e705c121SKalle Valo u32 hw_id; 1075e705c121SKalle Valo char hw_id_str[52]; 107690824f2fSLuca Coelho u32 sku_id[3]; 1077e705c121SKalle Valo 1078e705c121SKalle Valo u8 rx_mpdu_cmd, rx_mpdu_cmd_hdr_size; 1079e705c121SKalle Valo 1080e705c121SKalle Valo bool pm_support; 1081e705c121SKalle Valo bool ltr_enabled; 108269725928SLuca Coelho u8 pnvm_loaded:1; 1083b99e32cbSAlon Giladi u8 fail_to_parse_pnvm_image:1; 10849dad325fSLuca Coelho u8 reduce_power_loaded:1; 1085e705c121SKalle Valo 108639bdb17eSSharon Dvir const struct iwl_hcmd_arr *command_groups; 108739bdb17eSSharon Dvir int command_groups_size; 1088b7d96bcaSLuca Coelho bool wide_cmd_header; 108939bdb17eSSharon Dvir 109013f028b4SMordechay Goodstein wait_queue_head_t wait_command_queue; 1091e705c121SKalle Valo u8 num_rx_queues; 1092e705c121SKalle Valo 1093132db31cSGolan Ben-Ami size_t iml_len; 1094132db31cSGolan Ben-Ami u8 *iml; 1095132db31cSGolan Ben-Ami 1096e705c121SKalle Valo /* The following fields are internal only */ 1097e705c121SKalle Valo struct kmem_cache *dev_cmd_pool; 1098e705c121SKalle Valo char dev_cmd_pool_name[50]; 1099e705c121SKalle Valo 1100e705c121SKalle Valo struct dentry *dbgfs_dir; 1101e705c121SKalle Valo 1102e705c121SKalle Valo #ifdef CONFIG_LOCKDEP 1103e705c121SKalle Valo struct lockdep_map sync_cmd_lockdep_map; 1104e705c121SKalle Valo #endif 1105e705c121SKalle Valo 110691c28b83SShahar S Matityahu struct iwl_trans_debug dbg; 1107505a00c0SShahar S Matityahu struct iwl_self_init_dram init_dram; 1108e705c121SKalle Valo 1109b7282643SLuca Coelho enum iwl_plat_pm_mode system_pm_mode; 1110700b3799SShahar S Matityahu 11110b295a1eSLuca Coelho const char *name; 11124f4822b7SMordechay Goodstein struct iwl_trans_txqs txqs; 111309b4c35dSAyala Barazani u32 mbx_addr_0_step; 111409b4c35dSAyala Barazani u32 mbx_addr_1_step; 11150b295a1eSLuca Coelho 1116e705c121SKalle Valo /* pointer to trans specific struct */ 1117e705c121SKalle Valo /*Ensure that this pointer will always be aligned to sizeof pointer */ 111845c21a0eSGustavo A. R. Silva char trans_specific[] __aligned(sizeof(void *)); 1119e705c121SKalle Valo }; 1120e705c121SKalle Valo 112139bdb17eSSharon Dvir const char *iwl_get_cmd_string(struct iwl_trans *trans, u32 id); 112239bdb17eSSharon Dvir int iwl_cmd_groups_verify_sorted(const struct iwl_trans_config *trans); 112339bdb17eSSharon Dvir 1124e705c121SKalle Valo static inline void iwl_trans_configure(struct iwl_trans *trans, 1125e705c121SKalle Valo const struct iwl_trans_config *trans_cfg) 1126e705c121SKalle Valo { 1127e705c121SKalle Valo trans->op_mode = trans_cfg->op_mode; 1128e705c121SKalle Valo 1129e705c121SKalle Valo trans->ops->configure(trans, trans_cfg); 113039bdb17eSSharon Dvir WARN_ON(iwl_cmd_groups_verify_sorted(trans_cfg)); 1131e705c121SKalle Valo } 1132e705c121SKalle Valo 1133bab3cb92SEmmanuel Grumbach static inline int iwl_trans_start_hw(struct iwl_trans *trans) 1134e705c121SKalle Valo { 1135e705c121SKalle Valo might_sleep(); 1136e705c121SKalle Valo 1137bab3cb92SEmmanuel Grumbach return trans->ops->start_hw(trans); 1138e705c121SKalle Valo } 1139e705c121SKalle Valo 1140e705c121SKalle Valo static inline void iwl_trans_op_mode_leave(struct iwl_trans *trans) 1141e705c121SKalle Valo { 1142e705c121SKalle Valo might_sleep(); 1143e705c121SKalle Valo 1144e705c121SKalle Valo if (trans->ops->op_mode_leave) 1145e705c121SKalle Valo trans->ops->op_mode_leave(trans); 1146e705c121SKalle Valo 1147e705c121SKalle Valo trans->op_mode = NULL; 1148e705c121SKalle Valo 1149e705c121SKalle Valo trans->state = IWL_TRANS_NO_FW; 1150e705c121SKalle Valo } 1151e705c121SKalle Valo 1152e705c121SKalle Valo static inline void iwl_trans_fw_alive(struct iwl_trans *trans, u32 scd_addr) 1153e705c121SKalle Valo { 1154e705c121SKalle Valo might_sleep(); 1155e705c121SKalle Valo 1156e705c121SKalle Valo trans->state = IWL_TRANS_FW_ALIVE; 1157e705c121SKalle Valo 1158e705c121SKalle Valo trans->ops->fw_alive(trans, scd_addr); 1159e705c121SKalle Valo } 1160e705c121SKalle Valo 1161e705c121SKalle Valo static inline int iwl_trans_start_fw(struct iwl_trans *trans, 1162e705c121SKalle Valo const struct fw_img *fw, 1163e705c121SKalle Valo bool run_in_rfkill) 1164e705c121SKalle Valo { 1165b2ed841eSJohannes Berg int ret; 1166b2ed841eSJohannes Berg 1167e705c121SKalle Valo might_sleep(); 1168e705c121SKalle Valo 1169e705c121SKalle Valo WARN_ON_ONCE(!trans->rx_mpdu_cmd); 1170e705c121SKalle Valo 1171e705c121SKalle Valo clear_bit(STATUS_FW_ERROR, &trans->status); 1172b2ed841eSJohannes Berg ret = trans->ops->start_fw(trans, fw, run_in_rfkill); 1173b2ed841eSJohannes Berg if (ret == 0) 1174b2ed841eSJohannes Berg trans->state = IWL_TRANS_FW_STARTED; 1175b2ed841eSJohannes Berg 1176b2ed841eSJohannes Berg return ret; 1177e705c121SKalle Valo } 1178e705c121SKalle Valo 1179bab3cb92SEmmanuel Grumbach static inline void iwl_trans_stop_device(struct iwl_trans *trans) 1180e705c121SKalle Valo { 1181e705c121SKalle Valo might_sleep(); 1182e705c121SKalle Valo 1183bab3cb92SEmmanuel Grumbach trans->ops->stop_device(trans); 1184e705c121SKalle Valo 1185e705c121SKalle Valo trans->state = IWL_TRANS_NO_FW; 1186e705c121SKalle Valo } 1187e705c121SKalle Valo 1188e5f3f215SHaim Dreyfuss static inline int iwl_trans_d3_suspend(struct iwl_trans *trans, bool test, 118923ae6128SMatti Gottlieb bool reset) 1190e705c121SKalle Valo { 1191e705c121SKalle Valo might_sleep(); 1192e5f3f215SHaim Dreyfuss if (!trans->ops->d3_suspend) 1193cad7850aSHaim Dreyfuss return -EOPNOTSUPP; 1194e5f3f215SHaim Dreyfuss 1195e5f3f215SHaim Dreyfuss return trans->ops->d3_suspend(trans, test, reset); 1196e705c121SKalle Valo } 1197e705c121SKalle Valo 1198e705c121SKalle Valo static inline int iwl_trans_d3_resume(struct iwl_trans *trans, 1199e705c121SKalle Valo enum iwl_d3_status *status, 120023ae6128SMatti Gottlieb bool test, bool reset) 1201e705c121SKalle Valo { 1202e705c121SKalle Valo might_sleep(); 1203e705c121SKalle Valo if (!trans->ops->d3_resume) 1204cad7850aSHaim Dreyfuss return -EOPNOTSUPP; 1205e705c121SKalle Valo 120623ae6128SMatti Gottlieb return trans->ops->d3_resume(trans, status, test, reset); 1207e705c121SKalle Valo } 1208e705c121SKalle Valo 1209e705c121SKalle Valo static inline struct iwl_trans_dump_data * 1210fdb70083SJohannes Berg iwl_trans_dump_data(struct iwl_trans *trans, u32 dump_mask, 1211fdb70083SJohannes Berg const struct iwl_dump_sanitize_ops *sanitize_ops, 1212fdb70083SJohannes Berg void *sanitize_ctx) 1213e705c121SKalle Valo { 1214e705c121SKalle Valo if (!trans->ops->dump_data) 1215e705c121SKalle Valo return NULL; 1216fdb70083SJohannes Berg return trans->ops->dump_data(trans, dump_mask, 1217fdb70083SJohannes Berg sanitize_ops, sanitize_ctx); 1218e705c121SKalle Valo } 1219e705c121SKalle Valo 1220a89c72ffSJohannes Berg static inline struct iwl_device_tx_cmd * 1221e705c121SKalle Valo iwl_trans_alloc_tx_cmd(struct iwl_trans *trans) 1222e705c121SKalle Valo { 1223a89c72ffSJohannes Berg return kmem_cache_zalloc(trans->dev_cmd_pool, GFP_ATOMIC); 1224e705c121SKalle Valo } 1225e705c121SKalle Valo 122692fe8343SEmmanuel Grumbach int iwl_trans_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd); 122792fe8343SEmmanuel Grumbach 1228e705c121SKalle Valo static inline void iwl_trans_free_tx_cmd(struct iwl_trans *trans, 1229a89c72ffSJohannes Berg struct iwl_device_tx_cmd *dev_cmd) 1230e705c121SKalle Valo { 12311ea423b0SLuca Coelho kmem_cache_free(trans->dev_cmd_pool, dev_cmd); 1232e705c121SKalle Valo } 1233e705c121SKalle Valo 1234e705c121SKalle Valo static inline int iwl_trans_tx(struct iwl_trans *trans, struct sk_buff *skb, 1235a89c72ffSJohannes Berg struct iwl_device_tx_cmd *dev_cmd, int queue) 1236e705c121SKalle Valo { 1237e705c121SKalle Valo if (unlikely(test_bit(STATUS_FW_ERROR, &trans->status))) 1238e705c121SKalle Valo return -EIO; 1239e705c121SKalle Valo 1240e5d15cb5SEliad Peller if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) { 1241e705c121SKalle Valo IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state); 1242e5d15cb5SEliad Peller return -EIO; 1243e5d15cb5SEliad Peller } 1244e705c121SKalle Valo 1245e705c121SKalle Valo return trans->ops->tx(trans, skb, dev_cmd, queue); 1246e705c121SKalle Valo } 1247e705c121SKalle Valo 1248e705c121SKalle Valo static inline void iwl_trans_reclaim(struct iwl_trans *trans, int queue, 1249e705c121SKalle Valo int ssn, struct sk_buff_head *skbs) 1250e705c121SKalle Valo { 1251e5d15cb5SEliad Peller if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) { 1252e705c121SKalle Valo IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state); 1253e5d15cb5SEliad Peller return; 1254e5d15cb5SEliad Peller } 1255e705c121SKalle Valo 1256e705c121SKalle Valo trans->ops->reclaim(trans, queue, ssn, skbs); 1257e705c121SKalle Valo } 1258e705c121SKalle Valo 1259ba7136f3SAlex Malamud static inline void iwl_trans_set_q_ptrs(struct iwl_trans *trans, int queue, 1260ba7136f3SAlex Malamud int ptr) 1261ba7136f3SAlex Malamud { 1262ba7136f3SAlex Malamud if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) { 1263ba7136f3SAlex Malamud IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state); 1264ba7136f3SAlex Malamud return; 1265ba7136f3SAlex Malamud } 1266ba7136f3SAlex Malamud 1267ba7136f3SAlex Malamud trans->ops->set_q_ptrs(trans, queue, ptr); 1268ba7136f3SAlex Malamud } 1269ba7136f3SAlex Malamud 1270e705c121SKalle Valo static inline void iwl_trans_txq_disable(struct iwl_trans *trans, int queue, 1271e705c121SKalle Valo bool configure_scd) 1272e705c121SKalle Valo { 1273e705c121SKalle Valo trans->ops->txq_disable(trans, queue, configure_scd); 1274e705c121SKalle Valo } 1275e705c121SKalle Valo 1276dcfbd67bSEmmanuel Grumbach static inline bool 1277e705c121SKalle Valo iwl_trans_txq_enable_cfg(struct iwl_trans *trans, int queue, u16 ssn, 1278e705c121SKalle Valo const struct iwl_trans_txq_scd_cfg *cfg, 1279e705c121SKalle Valo unsigned int queue_wdg_timeout) 1280e705c121SKalle Valo { 1281e705c121SKalle Valo might_sleep(); 1282e705c121SKalle Valo 1283e5d15cb5SEliad Peller if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) { 1284e705c121SKalle Valo IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state); 1285dcfbd67bSEmmanuel Grumbach return false; 1286e5d15cb5SEliad Peller } 1287e705c121SKalle Valo 1288dcfbd67bSEmmanuel Grumbach return trans->ops->txq_enable(trans, queue, ssn, 1289dcfbd67bSEmmanuel Grumbach cfg, queue_wdg_timeout); 1290e705c121SKalle Valo } 1291e705c121SKalle Valo 129292536c96SSara Sharon static inline int 129392536c96SSara Sharon iwl_trans_get_rxq_dma_data(struct iwl_trans *trans, int queue, 129492536c96SSara Sharon struct iwl_trans_rxq_dma_data *data) 129592536c96SSara Sharon { 129692536c96SSara Sharon if (WARN_ON_ONCE(!trans->ops->rxq_dma_data)) 129792536c96SSara Sharon return -ENOTSUPP; 129892536c96SSara Sharon 129992536c96SSara Sharon return trans->ops->rxq_dma_data(trans, queue, data); 130092536c96SSara Sharon } 130192536c96SSara Sharon 13026b35ff91SSara Sharon static inline void 13036b35ff91SSara Sharon iwl_trans_txq_free(struct iwl_trans *trans, int queue) 13046b35ff91SSara Sharon { 13056b35ff91SSara Sharon if (WARN_ON_ONCE(!trans->ops->txq_free)) 13066b35ff91SSara Sharon return; 13076b35ff91SSara Sharon 13086b35ff91SSara Sharon trans->ops->txq_free(trans, queue); 13096b35ff91SSara Sharon } 13106b35ff91SSara Sharon 13116b35ff91SSara Sharon static inline int 13126b35ff91SSara Sharon iwl_trans_txq_alloc(struct iwl_trans *trans, 1313227f2597SJohannes Berg u32 flags, u32 sta_mask, u8 tid, 131485b17a33SJohannes Berg int size, unsigned int wdg_timeout) 13156b35ff91SSara Sharon { 13166b35ff91SSara Sharon might_sleep(); 13176b35ff91SSara Sharon 13186b35ff91SSara Sharon if (WARN_ON_ONCE(!trans->ops->txq_alloc)) 13196b35ff91SSara Sharon return -ENOTSUPP; 13206b35ff91SSara Sharon 13216b35ff91SSara Sharon if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) { 13226b35ff91SSara Sharon IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state); 13236b35ff91SSara Sharon return -EIO; 13246b35ff91SSara Sharon } 13256b35ff91SSara Sharon 1326227f2597SJohannes Berg return trans->ops->txq_alloc(trans, flags, sta_mask, tid, 132785b17a33SJohannes Berg size, wdg_timeout); 13286b35ff91SSara Sharon } 13296b35ff91SSara Sharon 133042db09c1SLiad Kaufman static inline void iwl_trans_txq_set_shared_mode(struct iwl_trans *trans, 133142db09c1SLiad Kaufman int queue, bool shared_mode) 133242db09c1SLiad Kaufman { 133342db09c1SLiad Kaufman if (trans->ops->txq_set_shared_mode) 133442db09c1SLiad Kaufman trans->ops->txq_set_shared_mode(trans, queue, shared_mode); 133542db09c1SLiad Kaufman } 133642db09c1SLiad Kaufman 1337e705c121SKalle Valo static inline void iwl_trans_txq_enable(struct iwl_trans *trans, int queue, 1338e705c121SKalle Valo int fifo, int sta_id, int tid, 1339e705c121SKalle Valo int frame_limit, u16 ssn, 1340e705c121SKalle Valo unsigned int queue_wdg_timeout) 1341e705c121SKalle Valo { 1342e705c121SKalle Valo struct iwl_trans_txq_scd_cfg cfg = { 1343e705c121SKalle Valo .fifo = fifo, 1344e705c121SKalle Valo .sta_id = sta_id, 1345e705c121SKalle Valo .tid = tid, 1346e705c121SKalle Valo .frame_limit = frame_limit, 1347e705c121SKalle Valo .aggregate = sta_id >= 0, 1348e705c121SKalle Valo }; 1349e705c121SKalle Valo 1350e705c121SKalle Valo iwl_trans_txq_enable_cfg(trans, queue, ssn, &cfg, queue_wdg_timeout); 1351e705c121SKalle Valo } 1352e705c121SKalle Valo 1353e705c121SKalle Valo static inline 1354e705c121SKalle Valo void iwl_trans_ac_txq_enable(struct iwl_trans *trans, int queue, int fifo, 1355e705c121SKalle Valo unsigned int queue_wdg_timeout) 1356e705c121SKalle Valo { 1357e705c121SKalle Valo struct iwl_trans_txq_scd_cfg cfg = { 1358e705c121SKalle Valo .fifo = fifo, 1359e705c121SKalle Valo .sta_id = -1, 1360e705c121SKalle Valo .tid = IWL_MAX_TID_COUNT, 1361e705c121SKalle Valo .frame_limit = IWL_FRAME_LIMIT, 1362e705c121SKalle Valo .aggregate = false, 1363e705c121SKalle Valo }; 1364e705c121SKalle Valo 1365e705c121SKalle Valo iwl_trans_txq_enable_cfg(trans, queue, 0, &cfg, queue_wdg_timeout); 1366e705c121SKalle Valo } 1367e705c121SKalle Valo 1368e705c121SKalle Valo static inline void iwl_trans_freeze_txq_timer(struct iwl_trans *trans, 1369e705c121SKalle Valo unsigned long txqs, 1370e705c121SKalle Valo bool freeze) 1371e705c121SKalle Valo { 1372e5d15cb5SEliad Peller if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) { 1373e705c121SKalle Valo IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state); 1374e5d15cb5SEliad Peller return; 1375e5d15cb5SEliad Peller } 1376e705c121SKalle Valo 1377e705c121SKalle Valo if (trans->ops->freeze_txq_timer) 1378e705c121SKalle Valo trans->ops->freeze_txq_timer(trans, txqs, freeze); 1379e705c121SKalle Valo } 1380e705c121SKalle Valo 13810cd58eaaSEmmanuel Grumbach static inline void iwl_trans_block_txq_ptrs(struct iwl_trans *trans, 13820cd58eaaSEmmanuel Grumbach bool block) 13830cd58eaaSEmmanuel Grumbach { 1384e5d15cb5SEliad Peller if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) { 13850cd58eaaSEmmanuel Grumbach IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state); 1386e5d15cb5SEliad Peller return; 1387e5d15cb5SEliad Peller } 13880cd58eaaSEmmanuel Grumbach 13890cd58eaaSEmmanuel Grumbach if (trans->ops->block_txq_ptrs) 13900cd58eaaSEmmanuel Grumbach trans->ops->block_txq_ptrs(trans, block); 13910cd58eaaSEmmanuel Grumbach } 13920cd58eaaSEmmanuel Grumbach 1393a1a57877SSara Sharon static inline int iwl_trans_wait_tx_queues_empty(struct iwl_trans *trans, 1394e705c121SKalle Valo u32 txqs) 1395e705c121SKalle Valo { 1396d6d517b7SSara Sharon if (WARN_ON_ONCE(!trans->ops->wait_tx_queues_empty)) 1397d6d517b7SSara Sharon return -ENOTSUPP; 1398d6d517b7SSara Sharon 13992b84e632SEmmanuel Grumbach /* No need to wait if the firmware is not alive */ 14002b84e632SEmmanuel Grumbach if (trans->state != IWL_TRANS_FW_ALIVE) { 1401e705c121SKalle Valo IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state); 1402e5d15cb5SEliad Peller return -EIO; 1403e5d15cb5SEliad Peller } 1404e705c121SKalle Valo 1405a1a57877SSara Sharon return trans->ops->wait_tx_queues_empty(trans, txqs); 1406e705c121SKalle Valo } 1407e705c121SKalle Valo 1408d6d517b7SSara Sharon static inline int iwl_trans_wait_txq_empty(struct iwl_trans *trans, int queue) 1409d6d517b7SSara Sharon { 1410d6d517b7SSara Sharon if (WARN_ON_ONCE(!trans->ops->wait_txq_empty)) 1411d6d517b7SSara Sharon return -ENOTSUPP; 1412d6d517b7SSara Sharon 1413d6d517b7SSara Sharon if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) { 1414d6d517b7SSara Sharon IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state); 1415d6d517b7SSara Sharon return -EIO; 1416d6d517b7SSara Sharon } 1417d6d517b7SSara Sharon 1418d6d517b7SSara Sharon return trans->ops->wait_txq_empty(trans, queue); 1419d6d517b7SSara Sharon } 1420d6d517b7SSara Sharon 1421e705c121SKalle Valo static inline void iwl_trans_write8(struct iwl_trans *trans, u32 ofs, u8 val) 1422e705c121SKalle Valo { 1423e705c121SKalle Valo trans->ops->write8(trans, ofs, val); 1424e705c121SKalle Valo } 1425e705c121SKalle Valo 1426e705c121SKalle Valo static inline void iwl_trans_write32(struct iwl_trans *trans, u32 ofs, u32 val) 1427e705c121SKalle Valo { 1428e705c121SKalle Valo trans->ops->write32(trans, ofs, val); 1429e705c121SKalle Valo } 1430e705c121SKalle Valo 1431e705c121SKalle Valo static inline u32 iwl_trans_read32(struct iwl_trans *trans, u32 ofs) 1432e705c121SKalle Valo { 1433e705c121SKalle Valo return trans->ops->read32(trans, ofs); 1434e705c121SKalle Valo } 1435e705c121SKalle Valo 1436e705c121SKalle Valo static inline u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs) 1437e705c121SKalle Valo { 1438e705c121SKalle Valo return trans->ops->read_prph(trans, ofs); 1439e705c121SKalle Valo } 1440e705c121SKalle Valo 1441e705c121SKalle Valo static inline void iwl_trans_write_prph(struct iwl_trans *trans, u32 ofs, 1442e705c121SKalle Valo u32 val) 1443e705c121SKalle Valo { 1444e705c121SKalle Valo return trans->ops->write_prph(trans, ofs, val); 1445e705c121SKalle Valo } 1446e705c121SKalle Valo 1447e705c121SKalle Valo static inline int iwl_trans_read_mem(struct iwl_trans *trans, u32 addr, 1448e705c121SKalle Valo void *buf, int dwords) 1449e705c121SKalle Valo { 1450e705c121SKalle Valo return trans->ops->read_mem(trans, addr, buf, dwords); 1451e705c121SKalle Valo } 1452e705c121SKalle Valo 1453e705c121SKalle Valo #define iwl_trans_read_mem_bytes(trans, addr, buf, bufsize) \ 1454e705c121SKalle Valo do { \ 1455e705c121SKalle Valo if (__builtin_constant_p(bufsize)) \ 1456e705c121SKalle Valo BUILD_BUG_ON((bufsize) % sizeof(u32)); \ 1457e705c121SKalle Valo iwl_trans_read_mem(trans, addr, buf, (bufsize) / sizeof(u32));\ 1458e705c121SKalle Valo } while (0) 1459e705c121SKalle Valo 1460c0941aceSMukesh Sisodiya static inline int iwl_trans_write_imr_mem(struct iwl_trans *trans, 1461c0941aceSMukesh Sisodiya u32 dst_addr, u64 src_addr, 1462c0941aceSMukesh Sisodiya u32 byte_cnt) 1463c0941aceSMukesh Sisodiya { 1464c0941aceSMukesh Sisodiya if (trans->ops->imr_dma_data) 1465c0941aceSMukesh Sisodiya return trans->ops->imr_dma_data(trans, dst_addr, src_addr, byte_cnt); 1466c0941aceSMukesh Sisodiya return 0; 1467c0941aceSMukesh Sisodiya } 1468c0941aceSMukesh Sisodiya 1469e705c121SKalle Valo static inline u32 iwl_trans_read_mem32(struct iwl_trans *trans, u32 addr) 1470e705c121SKalle Valo { 1471e705c121SKalle Valo u32 value; 1472e705c121SKalle Valo 1473e705c121SKalle Valo if (WARN_ON(iwl_trans_read_mem(trans, addr, &value, 1))) 1474e705c121SKalle Valo return 0xa5a5a5a5; 1475e705c121SKalle Valo 1476e705c121SKalle Valo return value; 1477e705c121SKalle Valo } 1478e705c121SKalle Valo 1479e705c121SKalle Valo static inline int iwl_trans_write_mem(struct iwl_trans *trans, u32 addr, 1480e705c121SKalle Valo const void *buf, int dwords) 1481e705c121SKalle Valo { 1482e705c121SKalle Valo return trans->ops->write_mem(trans, addr, buf, dwords); 1483e705c121SKalle Valo } 1484e705c121SKalle Valo 1485e705c121SKalle Valo static inline u32 iwl_trans_write_mem32(struct iwl_trans *trans, u32 addr, 1486e705c121SKalle Valo u32 val) 1487e705c121SKalle Valo { 1488e705c121SKalle Valo return iwl_trans_write_mem(trans, addr, &val, 1); 1489e705c121SKalle Valo } 1490e705c121SKalle Valo 1491e705c121SKalle Valo static inline void iwl_trans_set_pmi(struct iwl_trans *trans, bool state) 1492e705c121SKalle Valo { 1493e705c121SKalle Valo if (trans->ops->set_pmi) 1494e705c121SKalle Valo trans->ops->set_pmi(trans, state); 1495e705c121SKalle Valo } 1496e705c121SKalle Valo 149715bf5ac6SJohannes Berg static inline int iwl_trans_sw_reset(struct iwl_trans *trans, 149815bf5ac6SJohannes Berg bool retake_ownership) 1499870c2a11SGolan Ben Ami { 1500870c2a11SGolan Ben Ami if (trans->ops->sw_reset) 150115bf5ac6SJohannes Berg return trans->ops->sw_reset(trans, retake_ownership); 150215bf5ac6SJohannes Berg return 0; 1503870c2a11SGolan Ben Ami } 1504870c2a11SGolan Ben Ami 1505e705c121SKalle Valo static inline void 1506e705c121SKalle Valo iwl_trans_set_bits_mask(struct iwl_trans *trans, u32 reg, u32 mask, u32 value) 1507e705c121SKalle Valo { 1508e705c121SKalle Valo trans->ops->set_bits_mask(trans, reg, mask, value); 1509e705c121SKalle Valo } 1510e705c121SKalle Valo 15111ed08f6fSJohannes Berg #define iwl_trans_grab_nic_access(trans) \ 1512e705c121SKalle Valo __cond_lock(nic_access, \ 15131ed08f6fSJohannes Berg likely((trans)->ops->grab_nic_access(trans))) 1514e705c121SKalle Valo 1515e705c121SKalle Valo static inline void __releases(nic_access) 15161ed08f6fSJohannes Berg iwl_trans_release_nic_access(struct iwl_trans *trans) 1517e705c121SKalle Valo { 15181ed08f6fSJohannes Berg trans->ops->release_nic_access(trans); 1519e705c121SKalle Valo __release(nic_access); 1520e705c121SKalle Valo } 1521e705c121SKalle Valo 1522b8221b0fSJohannes Berg static inline void iwl_trans_fw_error(struct iwl_trans *trans, bool sync) 1523e705c121SKalle Valo { 1524e705c121SKalle Valo if (WARN_ON_ONCE(!trans->op_mode)) 1525e705c121SKalle Valo return; 1526e705c121SKalle Valo 1527e705c121SKalle Valo /* prevent double restarts due to the same erroneous FW */ 1528152fdc0fSJohannes Berg if (!test_and_set_bit(STATUS_FW_ERROR, &trans->status)) { 1529b8221b0fSJohannes Berg iwl_op_mode_nic_error(trans->op_mode, sync); 1530152fdc0fSJohannes Berg trans->state = IWL_TRANS_NO_FW; 1531152fdc0fSJohannes Berg } 1532e705c121SKalle Valo } 1533e705c121SKalle Valo 1534068893b7SShahar S Matityahu static inline bool iwl_trans_fw_running(struct iwl_trans *trans) 1535068893b7SShahar S Matityahu { 1536068893b7SShahar S Matityahu return trans->state == IWL_TRANS_FW_ALIVE; 1537068893b7SShahar S Matityahu } 1538068893b7SShahar S Matityahu 1539d1967ce6SShahar S Matityahu static inline void iwl_trans_sync_nmi(struct iwl_trans *trans) 1540d1967ce6SShahar S Matityahu { 1541d1967ce6SShahar S Matityahu if (trans->ops->sync_nmi) 1542d1967ce6SShahar S Matityahu trans->ops->sync_nmi(trans); 1543d1967ce6SShahar S Matityahu } 1544d1967ce6SShahar S Matityahu 15453161a34dSMordechay Goodstein void iwl_trans_sync_nmi_with_addr(struct iwl_trans *trans, u32 inta_addr, 15463161a34dSMordechay Goodstein u32 sw_err_bit); 15473161a34dSMordechay Goodstein 1548194d1f84SAlon Giladi static inline int iwl_trans_load_pnvm(struct iwl_trans *trans, 154933182810SAlon Giladi const struct iwl_pnvm_image *pnvm_data, 155033182810SAlon Giladi const struct iwl_ucode_capabilities *capa) 1551a182dfabSLuca Coelho { 155233182810SAlon Giladi return trans->ops->load_pnvm(trans, pnvm_data, capa); 155369725928SLuca Coelho } 155469725928SLuca Coelho 155533182810SAlon Giladi static inline void iwl_trans_set_pnvm(struct iwl_trans *trans, 155633182810SAlon Giladi const struct iwl_ucode_capabilities *capa) 1557194d1f84SAlon Giladi { 1558194d1f84SAlon Giladi if (trans->ops->set_pnvm) 155933182810SAlon Giladi trans->ops->set_pnvm(trans, capa); 1560a182dfabSLuca Coelho } 1561a182dfabSLuca Coelho 1562*c738fb61SAlon Giladi static inline int iwl_trans_load_reduce_power(struct iwl_trans *trans, 1563*c738fb61SAlon Giladi const void *data, 1564*c738fb61SAlon Giladi u32 len) 15659dad325fSLuca Coelho { 1566*c738fb61SAlon Giladi return trans->ops->load_reduce_power(trans, data, len); 15679dad325fSLuca Coelho } 15689dad325fSLuca Coelho 1569*c738fb61SAlon Giladi static inline void iwl_trans_set_reduce_power(struct iwl_trans *trans) 1570*c738fb61SAlon Giladi { 1571*c738fb61SAlon Giladi if (trans->ops->set_reduce_power) 1572*c738fb61SAlon Giladi trans->ops->set_reduce_power(trans); 15739dad325fSLuca Coelho } 15749dad325fSLuca Coelho 1575a1af4c48SShahar S Matityahu static inline bool iwl_trans_dbg_ini_valid(struct iwl_trans *trans) 1576a1af4c48SShahar S Matityahu { 1577341bd290SShahar S Matityahu return trans->dbg.internal_ini_cfg != IWL_INI_CFG_STATE_NOT_LOADED || 1578341bd290SShahar S Matityahu trans->dbg.external_ini_cfg != IWL_INI_CFG_STATE_NOT_LOADED; 1579a1af4c48SShahar S Matityahu } 1580a1af4c48SShahar S Matityahu 15813161a34dSMordechay Goodstein static inline void iwl_trans_interrupts(struct iwl_trans *trans, bool enable) 15823161a34dSMordechay Goodstein { 15833161a34dSMordechay Goodstein if (trans->ops->interrupts) 15843161a34dSMordechay Goodstein trans->ops->interrupts(trans, enable); 15853161a34dSMordechay Goodstein } 15863161a34dSMordechay Goodstein 1587e705c121SKalle Valo /***************************************************** 1588e705c121SKalle Valo * transport helper functions 1589e705c121SKalle Valo *****************************************************/ 1590e705c121SKalle Valo struct iwl_trans *iwl_trans_alloc(unsigned int priv_size, 1591e705c121SKalle Valo struct device *dev, 1592a89c72ffSJohannes Berg const struct iwl_trans_ops *ops, 1593fda1bd0dSMordechay Goodstein const struct iwl_cfg_trans_params *cfg_trans); 1594d12455fdSJohannes Berg int iwl_trans_init(struct iwl_trans *trans); 1595e705c121SKalle Valo void iwl_trans_free(struct iwl_trans *trans); 1596e705c121SKalle Valo 1597e705c121SKalle Valo /***************************************************** 1598e705c121SKalle Valo * driver (transport) register/unregister functions 1599e705c121SKalle Valo ******************************************************/ 1600e705c121SKalle Valo int __must_check iwl_pci_register_driver(void); 1601e705c121SKalle Valo void iwl_pci_unregister_driver(void); 1602b8133439SAvraham Stern void iwl_trans_pcie_remove(struct iwl_trans *trans, bool rescan); 1603e705c121SKalle Valo 1604e705c121SKalle Valo #endif /* __iwl_trans_h__ */ 1605