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