forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
....@@ -5,10 +5,9 @@
55 *
66 * GPL LICENSE SUMMARY
77 *
8
- * Copyright(c) 2007 - 2015 Intel Corporation. All rights reserved.
98 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
109 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11
- * Copyright(c) 2018 Intel Corporation
10
+ * Copyright(c) 2007 - 2015, 2018 - 2020 Intel Corporation
1211 *
1312 * This program is free software; you can redistribute it and/or modify
1413 * it under the terms of version 2 of the GNU General Public License as
....@@ -19,11 +18,6 @@
1918 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2019 * General Public License for more details.
2120 *
22
- * You should have received a copy of the GNU General Public License
23
- * along with this program; if not, write to the Free Software
24
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
25
- * USA
26
- *
2721 * The full GNU General Public License is included in this distribution
2822 * in the file called COPYING.
2923 *
....@@ -33,10 +27,9 @@
3327 *
3428 * BSD LICENSE
3529 *
36
- * Copyright(c) 2005 - 2015 Intel Corporation. All rights reserved.
3730 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
3831 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
39
- * Copyright(c) 2018 Intel Corporation
32
+ * Copyright(c) 2007 - 2015, 2018 - 2020 Intel Corporation
4033 * All rights reserved.
4134 *
4235 * Redistribution and use in source and binary forms, with or without
....@@ -67,15 +60,15 @@
6760 *
6861 *****************************************************************************/
6962 #include <linux/pci.h>
70
-#include <linux/pci-aspm.h>
7163 #include <linux/interrupt.h>
7264 #include <linux/debugfs.h>
7365 #include <linux/sched.h>
7466 #include <linux/bitops.h>
7567 #include <linux/gfp.h>
7668 #include <linux/vmalloc.h>
77
-#include <linux/pm_runtime.h>
7869 #include <linux/module.h>
70
+#include <linux/wait.h>
71
+#include <linux/seq_file.h>
7972
8073 #include "iwl-drv.h"
8174 #include "iwl-trans.h"
....@@ -85,17 +78,21 @@
8578 #include "iwl-agn-hw.h"
8679 #include "fw/error-dump.h"
8780 #include "fw/dbg.h"
81
+#include "fw/api/tx.h"
8882 #include "internal.h"
8983 #include "iwl-fh.h"
84
+#include "iwl-context-info-gen3.h"
9085
9186 /* extended range in FW SRAM */
9287 #define IWL_FW_MEM_EXTENDED_START 0x40000
9388 #define IWL_FW_MEM_EXTENDED_END 0x57FFF
9489
95
-static void iwl_trans_pcie_dump_regs(struct iwl_trans *trans)
90
+void iwl_trans_pcie_dump_regs(struct iwl_trans *trans)
9691 {
97
-#define PCI_DUMP_SIZE 64
98
-#define PREFIX_LEN 32
92
+#define PCI_DUMP_SIZE 352
93
+#define PCI_MEM_DUMP_SIZE 64
94
+#define PCI_PARENT_DUMP_SIZE 524
95
+#define PREFIX_LEN 32
9996 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
10097 struct pci_dev *pdev = trans_pcie->pci_dev;
10198 u32 i, pos, alloc_size, *ptr, *buf;
....@@ -106,11 +103,15 @@
106103
107104 /* Should be a multiple of 4 */
108105 BUILD_BUG_ON(PCI_DUMP_SIZE > 4096 || PCI_DUMP_SIZE & 0x3);
106
+ BUILD_BUG_ON(PCI_MEM_DUMP_SIZE > 4096 || PCI_MEM_DUMP_SIZE & 0x3);
107
+ BUILD_BUG_ON(PCI_PARENT_DUMP_SIZE > 4096 || PCI_PARENT_DUMP_SIZE & 0x3);
108
+
109109 /* Alloc a max size buffer */
110
- if (PCI_ERR_ROOT_ERR_SRC + 4 > PCI_DUMP_SIZE)
111
- alloc_size = PCI_ERR_ROOT_ERR_SRC + 4 + PREFIX_LEN;
112
- else
113
- alloc_size = PCI_DUMP_SIZE + PREFIX_LEN;
110
+ alloc_size = PCI_ERR_ROOT_ERR_SRC + 4 + PREFIX_LEN;
111
+ alloc_size = max_t(u32, alloc_size, PCI_DUMP_SIZE + PREFIX_LEN);
112
+ alloc_size = max_t(u32, alloc_size, PCI_MEM_DUMP_SIZE + PREFIX_LEN);
113
+ alloc_size = max_t(u32, alloc_size, PCI_PARENT_DUMP_SIZE + PREFIX_LEN);
114
+
114115 buf = kmalloc(alloc_size, GFP_ATOMIC);
115116 if (!buf)
116117 return;
....@@ -127,7 +128,7 @@
127128 print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET, 32, 4, buf, i, 0);
128129
129130 IWL_ERR(trans, "iwlwifi device memory mapped registers:\n");
130
- for (i = 0, ptr = buf; i < PCI_DUMP_SIZE; i += 4, ptr++)
131
+ for (i = 0, ptr = buf; i < PCI_MEM_DUMP_SIZE; i += 4, ptr++)
131132 *ptr = iwl_read32(trans, i);
132133 print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET, 32, 4, buf, i, 0);
133134
....@@ -150,7 +151,7 @@
150151
151152 IWL_ERR(trans, "iwlwifi parent port (%s) config registers:\n",
152153 pci_name(pdev));
153
- for (i = 0, ptr = buf; i < PCI_DUMP_SIZE; i += 4, ptr++)
154
+ for (i = 0, ptr = buf; i < PCI_PARENT_DUMP_SIZE; i += 4, ptr++)
154155 if (pci_read_config_dword(pdev, i, ptr))
155156 goto err_read;
156157 print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET, 32, 4, buf, i, 0);
....@@ -183,35 +184,66 @@
183184 static void iwl_trans_pcie_sw_reset(struct iwl_trans *trans)
184185 {
185186 /* Reset entire device - do controller reset (results in SHRD_HW_RST) */
186
- iwl_set_bit(trans, trans->cfg->csr->addr_sw_reset,
187
- BIT(trans->cfg->csr->flag_sw_reset));
187
+ iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
188188 usleep_range(5000, 6000);
189189 }
190190
191191 static void iwl_pcie_free_fw_monitor(struct iwl_trans *trans)
192192 {
193
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
193
+ struct iwl_dram_data *fw_mon = &trans->dbg.fw_mon;
194194
195
- if (!trans_pcie->fw_mon_page)
195
+ if (!fw_mon->size)
196196 return;
197197
198
- dma_unmap_page(trans->dev, trans_pcie->fw_mon_phys,
199
- trans_pcie->fw_mon_size, DMA_FROM_DEVICE);
200
- __free_pages(trans_pcie->fw_mon_page,
201
- get_order(trans_pcie->fw_mon_size));
202
- trans_pcie->fw_mon_page = NULL;
203
- trans_pcie->fw_mon_phys = 0;
204
- trans_pcie->fw_mon_size = 0;
198
+ dma_free_coherent(trans->dev, fw_mon->size, fw_mon->block,
199
+ fw_mon->physical);
200
+
201
+ fw_mon->block = NULL;
202
+ fw_mon->physical = 0;
203
+ fw_mon->size = 0;
204
+}
205
+
206
+static void iwl_pcie_alloc_fw_monitor_block(struct iwl_trans *trans,
207
+ u8 max_power, u8 min_power)
208
+{
209
+ struct iwl_dram_data *fw_mon = &trans->dbg.fw_mon;
210
+ void *block = NULL;
211
+ dma_addr_t physical = 0;
212
+ u32 size = 0;
213
+ u8 power;
214
+
215
+ if (fw_mon->size)
216
+ return;
217
+
218
+ for (power = max_power; power >= min_power; power--) {
219
+ size = BIT(power);
220
+ block = dma_alloc_coherent(trans->dev, size, &physical,
221
+ GFP_KERNEL | __GFP_NOWARN);
222
+ if (!block)
223
+ continue;
224
+
225
+ IWL_INFO(trans,
226
+ "Allocated 0x%08x bytes for firmware monitor.\n",
227
+ size);
228
+ break;
229
+ }
230
+
231
+ if (WARN_ON_ONCE(!block))
232
+ return;
233
+
234
+ if (power != max_power)
235
+ IWL_ERR(trans,
236
+ "Sorry - debug buffer is only %luK while you requested %luK\n",
237
+ (unsigned long)BIT(power - 10),
238
+ (unsigned long)BIT(max_power - 10));
239
+
240
+ fw_mon->block = block;
241
+ fw_mon->physical = physical;
242
+ fw_mon->size = size;
205243 }
206244
207245 void iwl_pcie_alloc_fw_monitor(struct iwl_trans *trans, u8 max_power)
208246 {
209
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
210
- struct page *page = NULL;
211
- dma_addr_t phys;
212
- u32 size = 0;
213
- u8 power;
214
-
215247 if (!max_power) {
216248 /* default max_power is maximum */
217249 max_power = 26;
....@@ -224,49 +256,10 @@
224256 max_power))
225257 return;
226258
227
- if (trans_pcie->fw_mon_page) {
228
- dma_sync_single_for_device(trans->dev, trans_pcie->fw_mon_phys,
229
- trans_pcie->fw_mon_size,
230
- DMA_FROM_DEVICE);
231
- return;
232
- }
233
-
234
- phys = 0;
235
- for (power = max_power; power >= 11; power--) {
236
- int order;
237
-
238
- size = BIT(power);
239
- order = get_order(size);
240
- page = alloc_pages(__GFP_COMP | __GFP_NOWARN | __GFP_ZERO,
241
- order);
242
- if (!page)
243
- continue;
244
-
245
- phys = dma_map_page(trans->dev, page, 0, PAGE_SIZE << order,
246
- DMA_FROM_DEVICE);
247
- if (dma_mapping_error(trans->dev, phys)) {
248
- __free_pages(page, order);
249
- page = NULL;
250
- continue;
251
- }
252
- IWL_INFO(trans,
253
- "Allocated 0x%08x bytes (order %d) for firmware monitor.\n",
254
- size, order);
255
- break;
256
- }
257
-
258
- if (WARN_ON_ONCE(!page))
259
+ if (trans->dbg.fw_mon.size)
259260 return;
260261
261
- if (power != max_power)
262
- IWL_ERR(trans,
263
- "Sorry - debug buffer is only %luK while you requested %luK\n",
264
- (unsigned long)BIT(power - 10),
265
- (unsigned long)BIT(max_power - 10));
266
-
267
- trans_pcie->fw_mon_page = page;
268
- trans_pcie->fw_mon_phys = phys;
269
- trans_pcie->fw_mon_size = size;
262
+ iwl_pcie_alloc_fw_monitor_block(trans, max_power, 11);
270263 }
271264
272265 static u32 iwl_trans_pcie_read_shr(struct iwl_trans *trans, u32 reg)
....@@ -308,18 +301,13 @@
308301 u16 cap;
309302
310303 /*
311
- * HW bug W/A for instability in PCIe bus L0S->L1 transition.
312
- * Check if BIOS (or OS) enabled L1-ASPM on this device.
313
- * If so (likely), disable L0S, so device moves directly L0->L1;
314
- * costs negligible amount of power savings.
315
- * If not (unlikely), enable L0S, so there is at least some
316
- * power savings, even without L1.
304
+ * L0S states have been found to be unstable with our devices
305
+ * and in newer hardware they are not officially supported at
306
+ * all, so we must always set the L0S_DISABLED bit.
317307 */
308
+ iwl_set_bit(trans, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_DISABLED);
309
+
318310 pcie_capability_read_word(trans_pcie->pci_dev, PCI_EXP_LNKCTL, &lctl);
319
- if (lctl & PCI_EXP_LNKCTL_ASPM_L1)
320
- iwl_set_bit(trans, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
321
- else
322
- iwl_clear_bit(trans, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
323311 trans->pm_support = !(lctl & PCI_EXP_LNKCTL_ASPM_L0S);
324312
325313 pcie_capability_read_word(trans_pcie->pci_dev, PCI_EXP_DEVCTL2, &cap);
....@@ -346,7 +334,7 @@
346334 */
347335
348336 /* Disable L0S exit timer (platform NMI Work/Around) */
349
- if (trans->cfg->device_family < IWL_DEVICE_FAMILY_8000)
337
+ if (trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_8000)
350338 iwl_set_bit(trans, CSR_GIO_CHICKEN_BITS,
351339 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
352340
....@@ -370,29 +358,12 @@
370358 iwl_pcie_apm_config(trans);
371359
372360 /* Configure analog phase-lock-loop before activating to D0A */
373
- if (trans->cfg->base_params->pll_cfg)
361
+ if (trans->trans_cfg->base_params->pll_cfg)
374362 iwl_set_bit(trans, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
375363
376
- /*
377
- * Set "initialization complete" bit to move adapter from
378
- * D0U* --> D0A* (powered-up active) state.
379
- */
380
- iwl_set_bit(trans, CSR_GP_CNTRL,
381
- BIT(trans->cfg->csr->flag_init_done));
382
-
383
- /*
384
- * Wait for clock stabilization; once stabilized, access to
385
- * device-internal resources is supported, e.g. iwl_write_prph()
386
- * and accesses to uCode SRAM.
387
- */
388
- ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
389
- BIT(trans->cfg->csr->flag_mac_clock_ready),
390
- BIT(trans->cfg->csr->flag_mac_clock_ready),
391
- 25000);
392
- if (ret < 0) {
393
- IWL_ERR(trans, "Failed to init the card\n");
364
+ ret = iwl_finish_nic_init(trans, trans->trans_cfg);
365
+ if (ret)
394366 return ret;
395
- }
396367
397368 if (trans->cfg->host_interrupt_operation_mode) {
398369 /*
....@@ -462,23 +433,8 @@
462433
463434 iwl_trans_pcie_sw_reset(trans);
464435
465
- /*
466
- * Set "initialization complete" bit to move adapter from
467
- * D0U* --> D0A* (powered-up active) state.
468
- */
469
- iwl_set_bit(trans, CSR_GP_CNTRL,
470
- BIT(trans->cfg->csr->flag_init_done));
471
-
472
- /*
473
- * Wait for clock stabilization; once stabilized, access to
474
- * device-internal resources is possible.
475
- */
476
- ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
477
- BIT(trans->cfg->csr->flag_mac_clock_ready),
478
- BIT(trans->cfg->csr->flag_mac_clock_ready),
479
- 25000);
480
- if (WARN_ON(ret < 0)) {
481
- IWL_ERR(trans, "Access time out - failed to enable LP XTAL\n");
436
+ ret = iwl_finish_nic_init(trans, trans->trans_cfg);
437
+ if (WARN_ON(ret)) {
482438 /* Release XTAL ON request */
483439 __iwl_trans_pcie_clear_bit(trans, CSR_GP_CNTRL,
484440 CSR_GP_CNTRL_REG_FLAG_XTAL_ON);
....@@ -526,8 +482,7 @@
526482 * Clear "initialization complete" bit to move adapter from
527483 * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
528484 */
529
- iwl_clear_bit(trans, CSR_GP_CNTRL,
530
- BIT(trans->cfg->csr->flag_init_done));
485
+ iwl_clear_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
531486
532487 /* Activates XTAL resources monitor */
533488 __iwl_trans_pcie_set_bit(trans, CSR_MONITOR_CFG_REG,
....@@ -549,12 +504,11 @@
549504 int ret;
550505
551506 /* stop device's busmaster DMA activity */
552
- iwl_set_bit(trans, trans->cfg->csr->addr_sw_reset,
553
- BIT(trans->cfg->csr->flag_stop_master));
507
+ iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
554508
555
- ret = iwl_poll_bit(trans, trans->cfg->csr->addr_sw_reset,
556
- BIT(trans->cfg->csr->flag_master_dis),
557
- BIT(trans->cfg->csr->flag_master_dis), 100);
509
+ ret = iwl_poll_bit(trans, CSR_RESET,
510
+ CSR_RESET_REG_FLAG_MASTER_DISABLED,
511
+ CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
558512 if (ret < 0)
559513 IWL_WARN(trans, "Master Disable Timed Out, 100 usec\n");
560514
....@@ -570,10 +524,11 @@
570524 iwl_pcie_apm_init(trans);
571525
572526 /* inform ME that we are leaving */
573
- if (trans->cfg->device_family == IWL_DEVICE_FAMILY_7000)
527
+ if (trans->trans_cfg->device_family == IWL_DEVICE_FAMILY_7000)
574528 iwl_set_bits_prph(trans, APMG_PCIDEV_STT_REG,
575529 APMG_PCIDEV_STT_VAL_WAKE_ME);
576
- else if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000) {
530
+ else if (trans->trans_cfg->device_family >=
531
+ IWL_DEVICE_FAMILY_8000) {
577532 iwl_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG,
578533 CSR_RESET_LINK_PWR_MGMT_DISABLED);
579534 iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
....@@ -602,8 +557,7 @@
602557 * Clear "initialization complete" bit to move adapter from
603558 * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
604559 */
605
- iwl_clear_bit(trans, CSR_GP_CNTRL,
606
- BIT(trans->cfg->csr->flag_init_done));
560
+ iwl_clear_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
607561 }
608562
609563 static int iwl_pcie_nic_init(struct iwl_trans *trans)
....@@ -630,7 +584,7 @@
630584 if (iwl_pcie_tx_init(trans))
631585 return -ENOMEM;
632586
633
- if (trans->cfg->base_params->shadow_reg_enable) {
587
+ if (trans->trans_cfg->base_params->shadow_reg_enable) {
634588 /* enable shadow regs in HW */
635589 iwl_set_bit(trans, CSR_MAC_SHADOW_REG_CTRL, 0x800FFFFF);
636590 IWL_DEBUG_INFO(trans, "Enabling shadow registers in device\n");
....@@ -666,7 +620,6 @@
666620 int iwl_pcie_prepare_card_hw(struct iwl_trans *trans)
667621 {
668622 int ret;
669
- int t = 0;
670623 int iter;
671624
672625 IWL_DEBUG_INFO(trans, "iwl_trans_prepare_card_hw enter\n");
....@@ -681,6 +634,8 @@
681634 usleep_range(1000, 2000);
682635
683636 for (iter = 0; iter < 10; iter++) {
637
+ int t = 0;
638
+
684639 /* If HW is not ready, prepare the conditions to check again */
685640 iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
686641 CSR_HW_IF_CONFIG_REG_PREPARE);
....@@ -868,7 +823,7 @@
868823
869824 iwl_enable_interrupts(trans);
870825
871
- if (trans->cfg->use_tfh) {
826
+ if (trans->trans_cfg->use_tfh) {
872827 if (cpu == 1)
873828 iwl_write_prph(trans, UREG_UCODE_LOAD_STATUS,
874829 0xFFFF);
....@@ -928,11 +883,53 @@
928883 return 0;
929884 }
930885
886
+static void iwl_pcie_apply_destination_ini(struct iwl_trans *trans)
887
+{
888
+ enum iwl_fw_ini_allocation_id alloc_id = IWL_FW_INI_ALLOCATION_ID_DBGC1;
889
+ struct iwl_fw_ini_allocation_tlv *fw_mon_cfg =
890
+ &trans->dbg.fw_mon_cfg[alloc_id];
891
+ struct iwl_dram_data *frag;
892
+
893
+ if (!iwl_trans_dbg_ini_valid(trans))
894
+ return;
895
+
896
+ if (le32_to_cpu(fw_mon_cfg->buf_location) ==
897
+ IWL_FW_INI_LOCATION_SRAM_PATH) {
898
+ IWL_DEBUG_FW(trans, "WRT: Applying SMEM buffer destination\n");
899
+ /* set sram monitor by enabling bit 7 */
900
+ iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
901
+ CSR_HW_IF_CONFIG_REG_BIT_MONITOR_SRAM);
902
+
903
+ return;
904
+ }
905
+
906
+ if (le32_to_cpu(fw_mon_cfg->buf_location) !=
907
+ IWL_FW_INI_LOCATION_DRAM_PATH ||
908
+ !trans->dbg.fw_mon_ini[alloc_id].num_frags)
909
+ return;
910
+
911
+ frag = &trans->dbg.fw_mon_ini[alloc_id].frags[0];
912
+
913
+ IWL_DEBUG_FW(trans, "WRT: Applying DRAM destination (alloc_id=%u)\n",
914
+ alloc_id);
915
+
916
+ iwl_write_umac_prph(trans, MON_BUFF_BASE_ADDR_VER2,
917
+ frag->physical >> MON_BUFF_SHIFT_VER2);
918
+ iwl_write_umac_prph(trans, MON_BUFF_END_ADDR_VER2,
919
+ (frag->physical + frag->size - 256) >>
920
+ MON_BUFF_SHIFT_VER2);
921
+}
922
+
931923 void iwl_pcie_apply_destination(struct iwl_trans *trans)
932924 {
933
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
934
- const struct iwl_fw_dbg_dest_tlv_v1 *dest = trans->dbg_dest_tlv;
925
+ const struct iwl_fw_dbg_dest_tlv_v1 *dest = trans->dbg.dest_tlv;
926
+ const struct iwl_dram_data *fw_mon = &trans->dbg.fw_mon;
935927 int i;
928
+
929
+ if (iwl_trans_dbg_ini_valid(trans)) {
930
+ iwl_pcie_apply_destination_ini(trans);
931
+ return;
932
+ }
936933
937934 IWL_INFO(trans, "Applying debug destination %s\n",
938935 get_fw_dbg_mode_string(dest->monitor_mode));
....@@ -942,7 +939,7 @@
942939 else
943940 IWL_WARN(trans, "PCI should have external buffer debug\n");
944941
945
- for (i = 0; i < trans->dbg_dest_reg_num; i++) {
942
+ for (i = 0; i < trans->dbg.n_dest_reg; i++) {
946943 u32 addr = le32_to_cpu(dest->reg_ops[i].addr);
947944 u32 val = le32_to_cpu(dest->reg_ops[i].val);
948945
....@@ -981,26 +978,23 @@
981978 }
982979
983980 monitor:
984
- if (dest->monitor_mode == EXTERNAL_MODE && trans_pcie->fw_mon_size) {
981
+ if (dest->monitor_mode == EXTERNAL_MODE && fw_mon->size) {
985982 iwl_write_prph(trans, le32_to_cpu(dest->base_reg),
986
- trans_pcie->fw_mon_phys >> dest->base_shift);
987
- if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000)
983
+ fw_mon->physical >> dest->base_shift);
984
+ if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_8000)
988985 iwl_write_prph(trans, le32_to_cpu(dest->end_reg),
989
- (trans_pcie->fw_mon_phys +
990
- trans_pcie->fw_mon_size - 256) >>
991
- dest->end_shift);
986
+ (fw_mon->physical + fw_mon->size -
987
+ 256) >> dest->end_shift);
992988 else
993989 iwl_write_prph(trans, le32_to_cpu(dest->end_reg),
994
- (trans_pcie->fw_mon_phys +
995
- trans_pcie->fw_mon_size) >>
996
- dest->end_shift);
990
+ (fw_mon->physical + fw_mon->size) >>
991
+ dest->end_shift);
997992 }
998993 }
999994
1000995 static int iwl_pcie_load_given_ucode(struct iwl_trans *trans,
1001996 const struct fw_img *image)
1002997 {
1003
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1004998 int ret = 0;
1005999 int first_ucode_section;
10061000
....@@ -1025,21 +1019,8 @@
10251019 return ret;
10261020 }
10271021
1028
- /* supported for 7000 only for the moment */
1029
- if (iwlwifi_mod_params.fw_monitor &&
1030
- trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
1031
- iwl_pcie_alloc_fw_monitor(trans, 0);
1032
-
1033
- if (trans_pcie->fw_mon_size) {
1034
- iwl_write_prph(trans, MON_BUFF_BASE_ADDR,
1035
- trans_pcie->fw_mon_phys >> 4);
1036
- iwl_write_prph(trans, MON_BUFF_END_ADDR,
1037
- (trans_pcie->fw_mon_phys +
1038
- trans_pcie->fw_mon_size) >> 4);
1039
- }
1040
- } else if (trans->dbg_dest_tlv) {
1022
+ if (iwl_pcie_dbg_on(trans))
10411023 iwl_pcie_apply_destination(trans);
1042
- }
10431024
10441025 iwl_enable_interrupts(trans);
10451026
....@@ -1058,7 +1039,7 @@
10581039 IWL_DEBUG_FW(trans, "working with %s CPU\n",
10591040 image->is_dual_cpus ? "Dual" : "Single");
10601041
1061
- if (trans->dbg_dest_tlv)
1042
+ if (iwl_pcie_dbg_on(trans))
10621043 iwl_pcie_apply_destination(trans);
10631044
10641045 IWL_DEBUG_POWER(trans, "Original WFPM value = 0x%08X\n",
....@@ -1123,6 +1104,7 @@
11231104 {MSIX_FH_INT_CAUSES_FH_ERR, CSR_MSIX_FH_INT_MASK_AD, 0x5},
11241105 {MSIX_HW_INT_CAUSES_REG_ALIVE, CSR_MSIX_HW_INT_MASK_AD, 0x10},
11251106 {MSIX_HW_INT_CAUSES_REG_WAKEUP, CSR_MSIX_HW_INT_MASK_AD, 0x11},
1107
+ {MSIX_HW_INT_CAUSES_REG_IML, CSR_MSIX_HW_INT_MASK_AD, 0x12},
11261108 {MSIX_HW_INT_CAUSES_REG_CT_KILL, CSR_MSIX_HW_INT_MASK_AD, 0x16},
11271109 {MSIX_HW_INT_CAUSES_REG_RF_KILL, CSR_MSIX_HW_INT_MASK_AD, 0x17},
11281110 {MSIX_HW_INT_CAUSES_REG_PERIODIC, CSR_MSIX_HW_INT_MASK_AD, 0x18},
....@@ -1133,30 +1115,12 @@
11331115 {MSIX_HW_INT_CAUSES_REG_HAP, CSR_MSIX_HW_INT_MASK_AD, 0x2E},
11341116 };
11351117
1136
-static struct iwl_causes_list causes_list_v2[] = {
1137
- {MSIX_FH_INT_CAUSES_D2S_CH0_NUM, CSR_MSIX_FH_INT_MASK_AD, 0},
1138
- {MSIX_FH_INT_CAUSES_D2S_CH1_NUM, CSR_MSIX_FH_INT_MASK_AD, 0x1},
1139
- {MSIX_FH_INT_CAUSES_S2D, CSR_MSIX_FH_INT_MASK_AD, 0x3},
1140
- {MSIX_FH_INT_CAUSES_FH_ERR, CSR_MSIX_FH_INT_MASK_AD, 0x5},
1141
- {MSIX_HW_INT_CAUSES_REG_ALIVE, CSR_MSIX_HW_INT_MASK_AD, 0x10},
1142
- {MSIX_HW_INT_CAUSES_REG_IPC, CSR_MSIX_HW_INT_MASK_AD, 0x11},
1143
- {MSIX_HW_INT_CAUSES_REG_SW_ERR_V2, CSR_MSIX_HW_INT_MASK_AD, 0x15},
1144
- {MSIX_HW_INT_CAUSES_REG_CT_KILL, CSR_MSIX_HW_INT_MASK_AD, 0x16},
1145
- {MSIX_HW_INT_CAUSES_REG_RF_KILL, CSR_MSIX_HW_INT_MASK_AD, 0x17},
1146
- {MSIX_HW_INT_CAUSES_REG_PERIODIC, CSR_MSIX_HW_INT_MASK_AD, 0x18},
1147
- {MSIX_HW_INT_CAUSES_REG_SCD, CSR_MSIX_HW_INT_MASK_AD, 0x2A},
1148
- {MSIX_HW_INT_CAUSES_REG_FH_TX, CSR_MSIX_HW_INT_MASK_AD, 0x2B},
1149
- {MSIX_HW_INT_CAUSES_REG_HW_ERR, CSR_MSIX_HW_INT_MASK_AD, 0x2D},
1150
- {MSIX_HW_INT_CAUSES_REG_HAP, CSR_MSIX_HW_INT_MASK_AD, 0x2E},
1151
-};
1152
-
11531118 static void iwl_pcie_map_non_rx_causes(struct iwl_trans *trans)
11541119 {
11551120 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
11561121 int val = trans_pcie->def_irq | MSIX_NON_AUTO_CLEAR_CAUSE;
1157
- int i, arr_size =
1158
- (trans->cfg->device_family < IWL_DEVICE_FAMILY_22560) ?
1159
- ARRAY_SIZE(causes_list) : ARRAY_SIZE(causes_list_v2);
1122
+ int i, arr_size = ARRAY_SIZE(causes_list);
1123
+ struct iwl_causes_list *causes = causes_list;
11601124
11611125 /*
11621126 * Access all non RX causes and map them to the default irq.
....@@ -1164,10 +1128,6 @@
11641128 * the first interrupt vector will serve non-RX and FBQ causes.
11651129 */
11661130 for (i = 0; i < arr_size; i++) {
1167
- struct iwl_causes_list *causes =
1168
- (trans->cfg->device_family < IWL_DEVICE_FAMILY_22560) ?
1169
- causes_list : causes_list_v2;
1170
-
11711131 iwl_write8(trans, CSR_MSIX_IVAR(causes[i].addr), val);
11721132 iwl_clear_bit(trans, causes[i].mask_reg,
11731133 causes[i].cause_num);
....@@ -1209,10 +1169,10 @@
12091169 struct iwl_trans *trans = trans_pcie->trans;
12101170
12111171 if (!trans_pcie->msix_enabled) {
1212
- if (trans->cfg->mq_rx_supported &&
1172
+ if (trans->trans_cfg->mq_rx_supported &&
12131173 test_bit(STATUS_DEVICE_ENABLED, &trans->status))
1214
- iwl_write_prph(trans, UREG_CHICK,
1215
- UREG_CHICK_MSI_ENABLE);
1174
+ iwl_write_umac_prph(trans, UREG_CHICK,
1175
+ UREG_CHICK_MSI_ENABLE);
12161176 return;
12171177 }
12181178 /*
....@@ -1221,7 +1181,7 @@
12211181 * prph.
12221182 */
12231183 if (test_bit(STATUS_DEVICE_ENABLED, &trans->status))
1224
- iwl_write_prph(trans, UREG_CHICK, UREG_CHICK_MSIX_ENABLE);
1184
+ iwl_write_umac_prph(trans, UREG_CHICK, UREG_CHICK_MSIX_ENABLE);
12251185
12261186 /*
12271187 * Each cause from the causes list above and the RX causes is
....@@ -1250,7 +1210,7 @@
12501210 trans_pcie->hw_mask = trans_pcie->hw_init_mask;
12511211 }
12521212
1253
-static void _iwl_trans_pcie_stop_device(struct iwl_trans *trans, bool low_power)
1213
+static void _iwl_trans_pcie_stop_device(struct iwl_trans *trans)
12541214 {
12551215 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
12561216
....@@ -1260,15 +1220,6 @@
12601220 return;
12611221
12621222 trans_pcie->is_down = true;
1263
-
1264
- /* Stop dbgc before stopping device */
1265
- if (trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
1266
- iwl_set_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x100);
1267
- } else {
1268
- iwl_write_prph(trans, DBGC_IN_SAMPLE, 0);
1269
- udelay(100);
1270
- iwl_write_prph(trans, DBGC_OUT_CTRL, 0);
1271
- }
12721223
12731224 /* tell the device to stop sending interrupts */
12741225 iwl_disable_interrupts(trans);
....@@ -1299,7 +1250,7 @@
12991250
13001251 /* Make sure (redundant) we've released our request to stay awake */
13011252 iwl_clear_bit(trans, CSR_GP_CNTRL,
1302
- BIT(trans->cfg->csr->flag_mac_access_req));
1253
+ CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
13031254
13041255 /* Stop the device, and put it in low power state */
13051256 iwl_pcie_apm_stop(trans, false);
....@@ -1425,7 +1376,7 @@
14251376 iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
14261377
14271378 /* Load the given image to the HW */
1428
- if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000)
1379
+ if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_8000)
14291380 ret = iwl_pcie_load_given_ucode_8000(trans, fw);
14301381 else
14311382 ret = iwl_pcie_load_given_ucode(trans, fw);
....@@ -1475,7 +1426,7 @@
14751426 iwl_trans_pcie_rf_kill(trans, hw_rfkill);
14761427 }
14771428
1478
-static void iwl_trans_pcie_stop_device(struct iwl_trans *trans, bool low_power)
1429
+static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
14791430 {
14801431 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
14811432 bool was_in_rfkill;
....@@ -1483,7 +1434,7 @@
14831434 mutex_lock(&trans_pcie->mutex);
14841435 trans_pcie->opmode_down = true;
14851436 was_in_rfkill = test_bit(STATUS_RFKILL_OPMODE, &trans->status);
1486
- _iwl_trans_pcie_stop_device(trans, low_power);
1437
+ _iwl_trans_pcie_stop_device(trans);
14871438 iwl_trans_pcie_handle_stop_rfkill(trans, was_in_rfkill);
14881439 mutex_unlock(&trans_pcie->mutex);
14891440 }
....@@ -1498,22 +1449,16 @@
14981449 IWL_WARN(trans, "reporting RF_KILL (radio %s)\n",
14991450 state ? "disabled" : "enabled");
15001451 if (iwl_op_mode_hw_rf_kill(trans->op_mode, state)) {
1501
- if (trans->cfg->gen2)
1502
- _iwl_trans_pcie_gen2_stop_device(trans, true);
1452
+ if (trans->trans_cfg->gen2)
1453
+ _iwl_trans_pcie_gen2_stop_device(trans);
15031454 else
1504
- _iwl_trans_pcie_stop_device(trans, true);
1455
+ _iwl_trans_pcie_stop_device(trans);
15051456 }
15061457 }
15071458
1508
-static void iwl_trans_pcie_d3_suspend(struct iwl_trans *trans, bool test,
1509
- bool reset)
1459
+void iwl_pcie_d3_complete_suspend(struct iwl_trans *trans,
1460
+ bool test, bool reset)
15101461 {
1511
- if (!reset) {
1512
- /* Enable persistence mode to avoid reset */
1513
- iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
1514
- CSR_HW_IF_CONFIG_REG_PERSIST_MODE);
1515
- }
1516
-
15171462 iwl_disable_interrupts(trans);
15181463
15191464 /*
....@@ -1528,11 +1473,8 @@
15281473 iwl_pcie_synchronize_irqs(trans);
15291474
15301475 iwl_clear_bit(trans, CSR_GP_CNTRL,
1531
- BIT(trans->cfg->csr->flag_mac_access_req));
1532
- iwl_clear_bit(trans, CSR_GP_CNTRL,
1533
- BIT(trans->cfg->csr->flag_init_done));
1534
-
1535
- iwl_pcie_enable_rx_wake(trans, false);
1476
+ CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
1477
+ iwl_clear_bit(trans, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
15361478
15371479 if (reset) {
15381480 /*
....@@ -1546,6 +1488,38 @@
15461488 iwl_pcie_set_pwr(trans, true);
15471489 }
15481490
1491
+static int iwl_trans_pcie_d3_suspend(struct iwl_trans *trans, bool test,
1492
+ bool reset)
1493
+{
1494
+ int ret;
1495
+ struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1496
+
1497
+ if (!reset)
1498
+ /* Enable persistence mode to avoid reset */
1499
+ iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
1500
+ CSR_HW_IF_CONFIG_REG_PERSIST_MODE);
1501
+
1502
+ if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
1503
+ iwl_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6,
1504
+ UREG_DOORBELL_TO_ISR6_SUSPEND);
1505
+
1506
+ ret = wait_event_timeout(trans_pcie->sx_waitq,
1507
+ trans_pcie->sx_complete, 2 * HZ);
1508
+ /*
1509
+ * Invalidate it toward resume.
1510
+ */
1511
+ trans_pcie->sx_complete = false;
1512
+
1513
+ if (!ret) {
1514
+ IWL_ERR(trans, "Timeout entering D3\n");
1515
+ return -ETIMEDOUT;
1516
+ }
1517
+ }
1518
+ iwl_pcie_d3_complete_suspend(trans, test, reset);
1519
+
1520
+ return 0;
1521
+}
1522
+
15491523 static int iwl_trans_pcie_d3_resume(struct iwl_trans *trans,
15501524 enum iwl_d3_status *status,
15511525 bool test, bool reset)
....@@ -1557,27 +1531,15 @@
15571531 if (test) {
15581532 iwl_enable_interrupts(trans);
15591533 *status = IWL_D3_STATUS_ALIVE;
1560
- return 0;
1534
+ goto out;
15611535 }
15621536
1563
- iwl_pcie_enable_rx_wake(trans, true);
1564
-
15651537 iwl_set_bit(trans, CSR_GP_CNTRL,
1566
- BIT(trans->cfg->csr->flag_mac_access_req));
1567
- iwl_set_bit(trans, CSR_GP_CNTRL,
1568
- BIT(trans->cfg->csr->flag_init_done));
1538
+ CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
15691539
1570
- if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000)
1571
- udelay(2);
1572
-
1573
- ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
1574
- BIT(trans->cfg->csr->flag_mac_clock_ready),
1575
- BIT(trans->cfg->csr->flag_mac_clock_ready),
1576
- 25000);
1577
- if (ret < 0) {
1578
- IWL_ERR(trans, "Failed to resume the device (mac ready)\n");
1540
+ ret = iwl_finish_nic_init(trans, trans->trans_cfg);
1541
+ if (ret)
15791542 return ret;
1580
- }
15811543
15821544 /*
15831545 * Reconfigure IVAR table in case of MSIX or reset ict table in
....@@ -1595,7 +1557,7 @@
15951557
15961558 if (!reset) {
15971559 iwl_clear_bit(trans, CSR_GP_CNTRL,
1598
- BIT(trans->cfg->csr->flag_mac_access_req));
1560
+ CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
15991561 } else {
16001562 iwl_trans_pcie_tx_reset(trans);
16011563
....@@ -1608,7 +1570,7 @@
16081570 }
16091571
16101572 IWL_DEBUG_POWER(trans, "WFPM value upon resume = 0x%08X\n",
1611
- iwl_read_prph(trans, WFPM_GP2));
1573
+ iwl_read_umac_prph(trans, WFPM_GP2));
16121574
16131575 val = iwl_read32(trans, CSR_RESET);
16141576 if (val & CSR_RESET_REG_FLAG_NEVO_RESET)
....@@ -1616,20 +1578,45 @@
16161578 else
16171579 *status = IWL_D3_STATUS_ALIVE;
16181580
1581
+out:
1582
+ if (*status == IWL_D3_STATUS_ALIVE &&
1583
+ trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
1584
+ trans_pcie->sx_complete = false;
1585
+ iwl_write_umac_prph(trans, UREG_DOORBELL_TO_ISR6,
1586
+ UREG_DOORBELL_TO_ISR6_RESUME);
1587
+
1588
+ ret = wait_event_timeout(trans_pcie->sx_waitq,
1589
+ trans_pcie->sx_complete, 2 * HZ);
1590
+ /*
1591
+ * Invalidate it toward next suspend.
1592
+ */
1593
+ trans_pcie->sx_complete = false;
1594
+
1595
+ if (!ret) {
1596
+ IWL_ERR(trans, "Timeout exiting D3\n");
1597
+ return -ETIMEDOUT;
1598
+ }
1599
+ }
16191600 return 0;
16201601 }
16211602
1622
-static void iwl_pcie_set_interrupt_capa(struct pci_dev *pdev,
1623
- struct iwl_trans *trans)
1603
+static void
1604
+iwl_pcie_set_interrupt_capa(struct pci_dev *pdev,
1605
+ struct iwl_trans *trans,
1606
+ const struct iwl_cfg_trans_params *cfg_trans)
16241607 {
16251608 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
16261609 int max_irqs, num_irqs, i, ret;
16271610 u16 pci_cmd;
1611
+ u32 max_rx_queues = IWL_MAX_RX_HW_QUEUES;
16281612
1629
- if (!trans->cfg->mq_rx_supported)
1613
+ if (!cfg_trans->mq_rx_supported)
16301614 goto enable_msi;
16311615
1632
- max_irqs = min_t(u32, num_online_cpus() + 2, IWL_MAX_RX_HW_QUEUES);
1616
+ if (cfg_trans->device_family <= IWL_DEVICE_FAMILY_9000)
1617
+ max_rx_queues = IWL_9000_MAX_RX_HW_QUEUES;
1618
+
1619
+ max_irqs = min_t(u32, num_online_cpus() + 2, max_rx_queues);
16331620 for (i = 0; i < max_irqs; i++)
16341621 trans_pcie->msix_entries[i].entry = i;
16351622
....@@ -1743,10 +1730,63 @@
17431730 return 0;
17441731 }
17451732
1746
-static int _iwl_trans_pcie_start_hw(struct iwl_trans *trans, bool low_power)
1733
+static int iwl_trans_pcie_clear_persistence_bit(struct iwl_trans *trans)
1734
+{
1735
+ u32 hpm, wprot;
1736
+
1737
+ switch (trans->trans_cfg->device_family) {
1738
+ case IWL_DEVICE_FAMILY_9000:
1739
+ wprot = PREG_PRPH_WPROT_9000;
1740
+ break;
1741
+ case IWL_DEVICE_FAMILY_22000:
1742
+ wprot = PREG_PRPH_WPROT_22000;
1743
+ break;
1744
+ default:
1745
+ return 0;
1746
+ }
1747
+
1748
+ hpm = iwl_read_umac_prph_no_grab(trans, HPM_DEBUG);
1749
+ if (hpm != 0xa5a5a5a0 && (hpm & PERSISTENCE_BIT)) {
1750
+ u32 wprot_val = iwl_read_umac_prph_no_grab(trans, wprot);
1751
+
1752
+ if (wprot_val & PREG_WFPM_ACCESS) {
1753
+ IWL_ERR(trans,
1754
+ "Error, can not clear persistence bit\n");
1755
+ return -EPERM;
1756
+ }
1757
+ iwl_write_umac_prph_no_grab(trans, HPM_DEBUG,
1758
+ hpm & ~PERSISTENCE_BIT);
1759
+ }
1760
+
1761
+ return 0;
1762
+}
1763
+
1764
+static int iwl_pcie_gen2_force_power_gating(struct iwl_trans *trans)
1765
+{
1766
+ int ret;
1767
+
1768
+ ret = iwl_finish_nic_init(trans, trans->trans_cfg);
1769
+ if (ret < 0)
1770
+ return ret;
1771
+
1772
+ iwl_set_bits_prph(trans, HPM_HIPM_GEN_CFG,
1773
+ HPM_HIPM_GEN_CFG_CR_FORCE_ACTIVE);
1774
+ udelay(20);
1775
+ iwl_set_bits_prph(trans, HPM_HIPM_GEN_CFG,
1776
+ HPM_HIPM_GEN_CFG_CR_PG_EN |
1777
+ HPM_HIPM_GEN_CFG_CR_SLP_EN);
1778
+ udelay(20);
1779
+ iwl_clear_bits_prph(trans, HPM_HIPM_GEN_CFG,
1780
+ HPM_HIPM_GEN_CFG_CR_FORCE_ACTIVE);
1781
+
1782
+ iwl_trans_pcie_sw_reset(trans);
1783
+
1784
+ return 0;
1785
+}
1786
+
1787
+static int _iwl_trans_pcie_start_hw(struct iwl_trans *trans)
17471788 {
17481789 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1749
- u32 hpm;
17501790 int err;
17511791
17521792 lockdep_assert_held(&trans_pcie->mutex);
....@@ -1757,18 +1797,18 @@
17571797 return err;
17581798 }
17591799
1760
- hpm = iwl_trans_read_prph(trans, HPM_DEBUG);
1761
- if (hpm != 0xa5a5a5a0 && (hpm & PERSISTENCE_BIT)) {
1762
- if (iwl_trans_read_prph(trans, PREG_PRPH_WPROT_0) &
1763
- PREG_WFPM_ACCESS) {
1764
- IWL_ERR(trans,
1765
- "Error, can not clear persistence bit\n");
1766
- return -EPERM;
1767
- }
1768
- iwl_trans_write_prph(trans, HPM_DEBUG, hpm & ~PERSISTENCE_BIT);
1769
- }
1800
+ err = iwl_trans_pcie_clear_persistence_bit(trans);
1801
+ if (err)
1802
+ return err;
17701803
17711804 iwl_trans_pcie_sw_reset(trans);
1805
+
1806
+ if (trans->trans_cfg->device_family == IWL_DEVICE_FAMILY_22000 &&
1807
+ trans->trans_cfg->integrated) {
1808
+ err = iwl_pcie_gen2_force_power_gating(trans);
1809
+ if (err)
1810
+ return err;
1811
+ }
17721812
17731813 err = iwl_pcie_apm_init(trans);
17741814 if (err)
....@@ -1787,20 +1827,16 @@
17871827 /* ...rfkill can call stop_device and set it false if needed */
17881828 iwl_pcie_check_hw_rf_kill(trans);
17891829
1790
- /* Make sure we sync here, because we'll need full access later */
1791
- if (low_power)
1792
- pm_runtime_resume(trans->dev);
1793
-
17941830 return 0;
17951831 }
17961832
1797
-static int iwl_trans_pcie_start_hw(struct iwl_trans *trans, bool low_power)
1833
+static int iwl_trans_pcie_start_hw(struct iwl_trans *trans)
17981834 {
17991835 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
18001836 int ret;
18011837
18021838 mutex_lock(&trans_pcie->mutex);
1803
- ret = _iwl_trans_pcie_start_hw(trans, low_power);
1839
+ ret = _iwl_trans_pcie_start_hw(trans);
18041840 mutex_unlock(&trans_pcie->mutex);
18051841
18061842 return ret;
....@@ -1843,7 +1879,7 @@
18431879
18441880 static u32 iwl_trans_pcie_prph_msk(struct iwl_trans *trans)
18451881 {
1846
- if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_22560)
1882
+ if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)
18471883 return 0x00FFFFFF;
18481884 else
18491885 return 0x000FFFFF;
....@@ -1873,9 +1909,15 @@
18731909 {
18741910 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
18751911
1876
- trans_pcie->cmd_queue = trans_cfg->cmd_queue;
1877
- trans_pcie->cmd_fifo = trans_cfg->cmd_fifo;
1878
- trans_pcie->cmd_q_wdg_timeout = trans_cfg->cmd_q_wdg_timeout;
1912
+ /* free all first - we might be reconfigured for a different size */
1913
+ iwl_pcie_free_rbs_pool(trans);
1914
+
1915
+ trans->txqs.cmd.q_id = trans_cfg->cmd_queue;
1916
+ trans->txqs.cmd.fifo = trans_cfg->cmd_fifo;
1917
+ trans->txqs.cmd.wdg_timeout = trans_cfg->cmd_q_wdg_timeout;
1918
+ trans->txqs.page_offs = trans_cfg->cb_data_offs;
1919
+ trans->txqs.dev_cmd_offs = trans_cfg->cb_data_offs + sizeof(void *);
1920
+
18791921 if (WARN_ON(trans_cfg->n_no_reclaim_cmds > MAX_NO_RECLAIM_CMDS))
18801922 trans_pcie->n_no_reclaim_cmds = 0;
18811923 else
....@@ -1887,13 +1929,15 @@
18871929 trans_pcie->rx_buf_size = trans_cfg->rx_buf_size;
18881930 trans_pcie->rx_page_order =
18891931 iwl_trans_get_rb_size_order(trans_pcie->rx_buf_size);
1932
+ trans_pcie->rx_buf_bytes =
1933
+ iwl_trans_get_rb_size(trans_pcie->rx_buf_size);
1934
+ trans_pcie->supported_dma_mask = DMA_BIT_MASK(12);
1935
+ if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)
1936
+ trans_pcie->supported_dma_mask = DMA_BIT_MASK(11);
18901937
1891
- trans_pcie->bc_table_dword = trans_cfg->bc_table_dword;
1938
+ trans->txqs.bc_table_dword = trans_cfg->bc_table_dword;
18921939 trans_pcie->scd_set_active = trans_cfg->scd_set_active;
18931940 trans_pcie->sw_csum_tx = trans_cfg->sw_csum_tx;
1894
-
1895
- trans_pcie->page_offs = trans_cfg->cb_data_offs;
1896
- trans_pcie->dev_cmd_offs = trans_cfg->cb_data_offs + sizeof(void *);
18971941
18981942 trans->command_groups = trans_cfg->command_groups;
18991943 trans->command_groups_size = trans_cfg->command_groups_size;
....@@ -1914,8 +1958,8 @@
19141958
19151959 iwl_pcie_synchronize_irqs(trans);
19161960
1917
- if (trans->cfg->gen2)
1918
- iwl_pcie_gen2_tx_free(trans);
1961
+ if (trans->trans_cfg->gen2)
1962
+ iwl_txq_gen2_tx_free(trans);
19191963 else
19201964 iwl_pcie_tx_free(trans);
19211965 iwl_pcie_rx_free(trans);
....@@ -1939,15 +1983,11 @@
19391983
19401984 iwl_pcie_free_fw_monitor(trans);
19411985
1942
- for_each_possible_cpu(i) {
1943
- struct iwl_tso_hdr_page *p =
1944
- per_cpu_ptr(trans_pcie->tso_hdr_page, i);
1986
+ if (trans_pcie->pnvm_dram.size)
1987
+ dma_free_coherent(trans->dev, trans_pcie->pnvm_dram.size,
1988
+ trans_pcie->pnvm_dram.block,
1989
+ trans_pcie->pnvm_dram.physical);
19451990
1946
- if (p->page)
1947
- __free_page(p->page);
1948
- }
1949
-
1950
- free_percpu(trans_pcie->tso_hdr_page);
19511991 mutex_destroy(&trans_pcie->mutex);
19521992 iwl_trans_free(trans);
19531993 }
....@@ -1970,7 +2010,7 @@
19702010 struct iwl_trans_pcie_removal *removal =
19712011 container_of(wk, struct iwl_trans_pcie_removal, work);
19722012 struct pci_dev *pdev = removal->pdev;
1973
- char *prop[] = {"EVENT=INACCESSIBLE", NULL};
2013
+ static char *prop[] = {"EVENT=INACCESSIBLE", NULL};
19742014
19752015 dev_err(&pdev->dev, "Device gone - attempting removal\n");
19762016 kobject_uevent_env(&pdev->dev.kobj, KOBJ_CHANGE, prop);
....@@ -1989,15 +2029,15 @@
19892029 int ret;
19902030 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
19912031
1992
- spin_lock_irqsave(&trans_pcie->reg_lock, *flags);
2032
+ spin_lock_bh(&trans_pcie->reg_lock);
19932033
19942034 if (trans_pcie->cmd_hold_nic_awake)
19952035 goto out;
19962036
19972037 /* this bit wakes up the NIC */
19982038 __iwl_trans_pcie_set_bit(trans, CSR_GP_CNTRL,
1999
- BIT(trans->cfg->csr->flag_mac_access_req));
2000
- if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000)
2039
+ CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
2040
+ if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_8000)
20012041 udelay(2);
20022042
20032043 /*
....@@ -2021,8 +2061,8 @@
20212061 * and do not save/restore SRAM when power cycling.
20222062 */
20232063 ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
2024
- BIT(trans->cfg->csr->flag_val_mac_access_en),
2025
- (BIT(trans->cfg->csr->flag_mac_clock_ready) |
2064
+ CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
2065
+ (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
20262066 CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
20272067 if (unlikely(ret < 0)) {
20282068 u32 cntrl = iwl_read32(trans, CSR_GP_CNTRL);
....@@ -2036,7 +2076,7 @@
20362076 if (iwlwifi_mod_params.remove_when_gone && cntrl == ~0U) {
20372077 struct iwl_trans_pcie_removal *removal;
20382078
2039
- if (trans_pcie->scheduled_for_removal)
2079
+ if (test_bit(STATUS_TRANS_DEAD, &trans->status))
20402080 goto err;
20412081
20422082 IWL_ERR(trans, "Device gone - scheduling removal!\n");
....@@ -2062,7 +2102,7 @@
20622102 * we don't need to clear this flag, because
20632103 * the trans will be freed and reallocated.
20642104 */
2065
- trans_pcie->scheduled_for_removal = true;
2105
+ set_bit(STATUS_TRANS_DEAD, &trans->status);
20662106
20672107 removal->pdev = to_pci_dev(trans->dev);
20682108 INIT_WORK(&removal->work, iwl_trans_pcie_removal_wk);
....@@ -2074,7 +2114,7 @@
20742114 }
20752115
20762116 err:
2077
- spin_unlock_irqrestore(&trans_pcie->reg_lock, *flags);
2117
+ spin_unlock_bh(&trans_pcie->reg_lock);
20782118 return false;
20792119 }
20802120
....@@ -2104,16 +2144,15 @@
21042144 goto out;
21052145
21062146 __iwl_trans_pcie_clear_bit(trans, CSR_GP_CNTRL,
2107
- BIT(trans->cfg->csr->flag_mac_access_req));
2147
+ CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
21082148 /*
21092149 * Above we read the CSR_GP_CNTRL register, which will flush
21102150 * any previous writes, but we need the write that clears the
21112151 * MAC_ACCESS_REQ bit to be performed before any other writes
21122152 * scheduled on different CPUs (after we drop reg_lock).
21132153 */
2114
- mmiowb();
21152154 out:
2116
- spin_unlock_irqrestore(&trans_pcie->reg_lock, *flags);
2155
+ spin_unlock_bh(&trans_pcie->reg_lock);
21172156 }
21182157
21192158 static int iwl_trans_pcie_read_mem(struct iwl_trans *trans, u32 addr,
....@@ -2173,15 +2212,21 @@
21732212 return ret;
21742213 }
21752214
2215
+static int iwl_trans_pcie_read_config32(struct iwl_trans *trans, u32 ofs,
2216
+ u32 *val)
2217
+{
2218
+ return pci_read_config_dword(IWL_TRANS_GET_PCIE_TRANS(trans)->pci_dev,
2219
+ ofs, val);
2220
+}
2221
+
21762222 static void iwl_trans_pcie_freeze_txq_timer(struct iwl_trans *trans,
21772223 unsigned long txqs,
21782224 bool freeze)
21792225 {
2180
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
21812226 int queue;
21822227
21832228 for_each_set_bit(queue, &txqs, BITS_PER_LONG) {
2184
- struct iwl_txq *txq = trans_pcie->txq[queue];
2229
+ struct iwl_txq *txq = trans->txqs.txq[queue];
21852230 unsigned long now;
21862231
21872232 spin_lock_bh(&txq->lock);
....@@ -2229,13 +2274,12 @@
22292274
22302275 static void iwl_trans_pcie_block_txq_ptrs(struct iwl_trans *trans, bool block)
22312276 {
2232
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
22332277 int i;
22342278
2235
- for (i = 0; i < trans->cfg->base_params->num_of_queues; i++) {
2236
- struct iwl_txq *txq = trans_pcie->txq[i];
2279
+ for (i = 0; i < trans->trans_cfg->base_params->num_of_queues; i++) {
2280
+ struct iwl_txq *txq = trans->txqs.txq[i];
22372281
2238
- if (i == trans_pcie->cmd_queue)
2282
+ if (i == trans->txqs.cmd.q_id)
22392283 continue;
22402284
22412285 spin_lock_bh(&txq->lock);
....@@ -2256,36 +2300,6 @@
22562300
22572301 #define IWL_FLUSH_WAIT_MS 2000
22582302
2259
-void iwl_trans_pcie_log_scd_error(struct iwl_trans *trans, struct iwl_txq *txq)
2260
-{
2261
- u32 txq_id = txq->id;
2262
- u32 status;
2263
- bool active;
2264
- u8 fifo;
2265
-
2266
- if (trans->cfg->use_tfh) {
2267
- IWL_ERR(trans, "Queue %d is stuck %d %d\n", txq_id,
2268
- txq->read_ptr, txq->write_ptr);
2269
- /* TODO: access new SCD registers and dump them */
2270
- return;
2271
- }
2272
-
2273
- status = iwl_read_prph(trans, SCD_QUEUE_STATUS_BITS(txq_id));
2274
- fifo = (status >> SCD_QUEUE_STTS_REG_POS_TXF) & 0x7;
2275
- active = !!(status & BIT(SCD_QUEUE_STTS_REG_POS_ACTIVE));
2276
-
2277
- IWL_ERR(trans,
2278
- "Queue %d is %sactive on fifo %d and stuck for %u ms. SW [%d, %d] HW [%d, %d] FH TRB=0x0%x\n",
2279
- txq_id, active ? "" : "in", fifo,
2280
- jiffies_to_msecs(txq->wd_timeout),
2281
- txq->read_ptr, txq->write_ptr,
2282
- iwl_read_prph(trans, SCD_QUEUE_RDPTR(txq_id)) &
2283
- (trans->cfg->base_params->max_tfd_queue_size - 1),
2284
- iwl_read_prph(trans, SCD_QUEUE_WRPTR(txq_id)) &
2285
- (trans->cfg->base_params->max_tfd_queue_size - 1),
2286
- iwl_read_direct32(trans, FH_TX_TRB_REG(fifo)));
2287
-}
2288
-
22892303 static int iwl_trans_pcie_rxq_dma_data(struct iwl_trans *trans, int queue,
22902304 struct iwl_trans_rxq_dma_data *data)
22912305 {
....@@ -2304,34 +2318,57 @@
23042318
23052319 static int iwl_trans_pcie_wait_txq_empty(struct iwl_trans *trans, int txq_idx)
23062320 {
2307
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
23082321 struct iwl_txq *txq;
23092322 unsigned long now = jiffies;
2323
+ bool overflow_tx;
23102324 u8 wr_ptr;
23112325
2312
- if (!test_bit(txq_idx, trans_pcie->queue_used))
2326
+ /* Make sure the NIC is still alive in the bus */
2327
+ if (test_bit(STATUS_TRANS_DEAD, &trans->status))
2328
+ return -ENODEV;
2329
+
2330
+ if (!test_bit(txq_idx, trans->txqs.queue_used))
23132331 return -EINVAL;
23142332
23152333 IWL_DEBUG_TX_QUEUES(trans, "Emptying queue %d...\n", txq_idx);
2316
- txq = trans_pcie->txq[txq_idx];
2334
+ txq = trans->txqs.txq[txq_idx];
2335
+
2336
+ spin_lock_bh(&txq->lock);
2337
+ overflow_tx = txq->overflow_tx ||
2338
+ !skb_queue_empty(&txq->overflow_q);
2339
+ spin_unlock_bh(&txq->lock);
2340
+
23172341 wr_ptr = READ_ONCE(txq->write_ptr);
23182342
2319
- while (txq->read_ptr != READ_ONCE(txq->write_ptr) &&
2343
+ while ((txq->read_ptr != READ_ONCE(txq->write_ptr) ||
2344
+ overflow_tx) &&
23202345 !time_after(jiffies,
23212346 now + msecs_to_jiffies(IWL_FLUSH_WAIT_MS))) {
23222347 u8 write_ptr = READ_ONCE(txq->write_ptr);
23232348
2324
- if (WARN_ONCE(wr_ptr != write_ptr,
2349
+ /*
2350
+ * If write pointer moved during the wait, warn only
2351
+ * if the TX came from op mode. In case TX came from
2352
+ * trans layer (overflow TX) don't warn.
2353
+ */
2354
+ if (WARN_ONCE(wr_ptr != write_ptr && !overflow_tx,
23252355 "WR pointer moved while flushing %d -> %d\n",
23262356 wr_ptr, write_ptr))
23272357 return -ETIMEDOUT;
2358
+ wr_ptr = write_ptr;
2359
+
23282360 usleep_range(1000, 2000);
2361
+
2362
+ spin_lock_bh(&txq->lock);
2363
+ overflow_tx = txq->overflow_tx ||
2364
+ !skb_queue_empty(&txq->overflow_q);
2365
+ spin_unlock_bh(&txq->lock);
23292366 }
23302367
23312368 if (txq->read_ptr != txq->write_ptr) {
23322369 IWL_ERR(trans,
23332370 "fail to flush all tx fifo queues Q %d\n", txq_idx);
2334
- iwl_trans_pcie_log_scd_error(trans, txq);
2371
+ iwl_txq_log_scd_error(trans, txq);
23352372 return -ETIMEDOUT;
23362373 }
23372374
....@@ -2342,16 +2379,17 @@
23422379
23432380 static int iwl_trans_pcie_wait_txqs_empty(struct iwl_trans *trans, u32 txq_bm)
23442381 {
2345
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
23462382 int cnt;
23472383 int ret = 0;
23482384
23492385 /* waiting for all the tx frames complete might take a while */
2350
- for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
2386
+ for (cnt = 0;
2387
+ cnt < trans->trans_cfg->base_params->num_of_queues;
2388
+ cnt++) {
23512389
2352
- if (cnt == trans_pcie->cmd_queue)
2390
+ if (cnt == trans->txqs.cmd.q_id)
23532391 continue;
2354
- if (!test_bit(cnt, trans_pcie->queue_used))
2392
+ if (!test_bit(cnt, trans->txqs.queue_used))
23552393 continue;
23562394 if (!(BIT(cnt) & txq_bm))
23572395 continue;
....@@ -2368,42 +2406,10 @@
23682406 u32 mask, u32 value)
23692407 {
23702408 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2371
- unsigned long flags;
23722409
2373
- spin_lock_irqsave(&trans_pcie->reg_lock, flags);
2410
+ spin_lock_bh(&trans_pcie->reg_lock);
23742411 __iwl_trans_pcie_set_bits_mask(trans, reg, mask, value);
2375
- spin_unlock_irqrestore(&trans_pcie->reg_lock, flags);
2376
-}
2377
-
2378
-static void iwl_trans_pcie_ref(struct iwl_trans *trans)
2379
-{
2380
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2381
-
2382
- if (iwlwifi_mod_params.d0i3_disable)
2383
- return;
2384
-
2385
- pm_runtime_get(&trans_pcie->pci_dev->dev);
2386
-
2387
-#ifdef CONFIG_PM
2388
- IWL_DEBUG_RPM(trans, "runtime usage count: %d\n",
2389
- atomic_read(&trans_pcie->pci_dev->dev.power.usage_count));
2390
-#endif /* CONFIG_PM */
2391
-}
2392
-
2393
-static void iwl_trans_pcie_unref(struct iwl_trans *trans)
2394
-{
2395
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2396
-
2397
- if (iwlwifi_mod_params.d0i3_disable)
2398
- return;
2399
-
2400
- pm_runtime_mark_last_busy(&trans_pcie->pci_dev->dev);
2401
- pm_runtime_put_autosuspend(&trans_pcie->pci_dev->dev);
2402
-
2403
-#ifdef CONFIG_PM
2404
- IWL_DEBUG_RPM(trans, "runtime usage count: %d\n",
2405
- atomic_read(&trans_pcie->pci_dev->dev.power.usage_count));
2406
-#endif /* CONFIG_PM */
2412
+ spin_unlock_bh(&trans_pcie->reg_lock);
24072413 }
24082414
24092415 static const char *get_csr_string(int cmd)
....@@ -2482,9 +2488,8 @@
24822488 #ifdef CONFIG_IWLWIFI_DEBUGFS
24832489 /* create and remove of files */
24842490 #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
2485
- if (!debugfs_create_file(#name, mode, parent, trans, \
2486
- &iwl_dbgfs_##name##_ops)) \
2487
- goto err; \
2491
+ debugfs_create_file(#name, mode, parent, trans, \
2492
+ &iwl_dbgfs_##name##_ops); \
24882493 } while (0)
24892494
24902495 /* file operation */
....@@ -2510,41 +2515,94 @@
25102515 .llseek = generic_file_llseek, \
25112516 };
25122517
2513
-static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
2514
- char __user *user_buf,
2515
- size_t count, loff_t *ppos)
2518
+struct iwl_dbgfs_tx_queue_priv {
2519
+ struct iwl_trans *trans;
2520
+};
2521
+
2522
+struct iwl_dbgfs_tx_queue_state {
2523
+ loff_t pos;
2524
+};
2525
+
2526
+static void *iwl_dbgfs_tx_queue_seq_start(struct seq_file *seq, loff_t *pos)
25162527 {
2517
- struct iwl_trans *trans = file->private_data;
2518
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2519
- struct iwl_txq *txq;
2520
- char *buf;
2521
- int pos = 0;
2522
- int cnt;
2523
- int ret;
2524
- size_t bufsz;
2528
+ struct iwl_dbgfs_tx_queue_priv *priv = seq->private;
2529
+ struct iwl_dbgfs_tx_queue_state *state;
25252530
2526
- bufsz = sizeof(char) * 75 * trans->cfg->base_params->num_of_queues;
2531
+ if (*pos >= priv->trans->trans_cfg->base_params->num_of_queues)
2532
+ return NULL;
25272533
2528
- if (!trans_pcie->txq_memory)
2529
- return -EAGAIN;
2534
+ state = kmalloc(sizeof(*state), GFP_KERNEL);
2535
+ if (!state)
2536
+ return NULL;
2537
+ state->pos = *pos;
2538
+ return state;
2539
+}
25302540
2531
- buf = kzalloc(bufsz, GFP_KERNEL);
2532
- if (!buf)
2541
+static void *iwl_dbgfs_tx_queue_seq_next(struct seq_file *seq,
2542
+ void *v, loff_t *pos)
2543
+{
2544
+ struct iwl_dbgfs_tx_queue_priv *priv = seq->private;
2545
+ struct iwl_dbgfs_tx_queue_state *state = v;
2546
+
2547
+ *pos = ++state->pos;
2548
+
2549
+ if (*pos >= priv->trans->trans_cfg->base_params->num_of_queues)
2550
+ return NULL;
2551
+
2552
+ return state;
2553
+}
2554
+
2555
+static void iwl_dbgfs_tx_queue_seq_stop(struct seq_file *seq, void *v)
2556
+{
2557
+ kfree(v);
2558
+}
2559
+
2560
+static int iwl_dbgfs_tx_queue_seq_show(struct seq_file *seq, void *v)
2561
+{
2562
+ struct iwl_dbgfs_tx_queue_priv *priv = seq->private;
2563
+ struct iwl_dbgfs_tx_queue_state *state = v;
2564
+ struct iwl_trans *trans = priv->trans;
2565
+ struct iwl_txq *txq = trans->txqs.txq[state->pos];
2566
+
2567
+ seq_printf(seq, "hwq %.3u: used=%d stopped=%d ",
2568
+ (unsigned int)state->pos,
2569
+ !!test_bit(state->pos, trans->txqs.queue_used),
2570
+ !!test_bit(state->pos, trans->txqs.queue_stopped));
2571
+ if (txq)
2572
+ seq_printf(seq,
2573
+ "read=%u write=%u need_update=%d frozen=%d n_window=%d ampdu=%d",
2574
+ txq->read_ptr, txq->write_ptr,
2575
+ txq->need_update, txq->frozen,
2576
+ txq->n_window, txq->ampdu);
2577
+ else
2578
+ seq_puts(seq, "(unallocated)");
2579
+
2580
+ if (state->pos == trans->txqs.cmd.q_id)
2581
+ seq_puts(seq, " (HCMD)");
2582
+ seq_puts(seq, "\n");
2583
+
2584
+ return 0;
2585
+}
2586
+
2587
+static const struct seq_operations iwl_dbgfs_tx_queue_seq_ops = {
2588
+ .start = iwl_dbgfs_tx_queue_seq_start,
2589
+ .next = iwl_dbgfs_tx_queue_seq_next,
2590
+ .stop = iwl_dbgfs_tx_queue_seq_stop,
2591
+ .show = iwl_dbgfs_tx_queue_seq_show,
2592
+};
2593
+
2594
+static int iwl_dbgfs_tx_queue_open(struct inode *inode, struct file *filp)
2595
+{
2596
+ struct iwl_dbgfs_tx_queue_priv *priv;
2597
+
2598
+ priv = __seq_open_private(filp, &iwl_dbgfs_tx_queue_seq_ops,
2599
+ sizeof(*priv));
2600
+
2601
+ if (!priv)
25332602 return -ENOMEM;
25342603
2535
- for (cnt = 0; cnt < trans->cfg->base_params->num_of_queues; cnt++) {
2536
- txq = trans_pcie->txq[cnt];
2537
- pos += scnprintf(buf + pos, bufsz - pos,
2538
- "hwq %.2d: read=%u write=%u use=%d stop=%d need_update=%d frozen=%d%s\n",
2539
- cnt, txq->read_ptr, txq->write_ptr,
2540
- !!test_bit(cnt, trans_pcie->queue_used),
2541
- !!test_bit(cnt, trans_pcie->queue_stopped),
2542
- txq->need_update, txq->frozen,
2543
- (cnt == trans_pcie->cmd_queue ? " HCMD" : ""));
2544
- }
2545
- ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2546
- kfree(buf);
2547
- return ret;
2604
+ priv->trans = inode->i_private;
2605
+ return 0;
25482606 }
25492607
25502608 static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
....@@ -2555,7 +2613,7 @@
25552613 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
25562614 char *buf;
25572615 int pos = 0, i, ret;
2558
- size_t bufsz = sizeof(buf);
2616
+ size_t bufsz;
25592617
25602618 bufsz = sizeof(char) * 121 * trans->num_rx_queues;
25612619
....@@ -2727,30 +2785,174 @@
27272785 {
27282786 struct iwl_trans *trans = file->private_data;
27292787 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2730
- bool old = trans_pcie->debug_rfkill;
2788
+ bool new_value;
27312789 int ret;
27322790
2733
- ret = kstrtobool_from_user(user_buf, count, &trans_pcie->debug_rfkill);
2791
+ ret = kstrtobool_from_user(user_buf, count, &new_value);
27342792 if (ret)
27352793 return ret;
2736
- if (old == trans_pcie->debug_rfkill)
2794
+ if (new_value == trans_pcie->debug_rfkill)
27372795 return count;
27382796 IWL_WARN(trans, "changing debug rfkill %d->%d\n",
2739
- old, trans_pcie->debug_rfkill);
2797
+ trans_pcie->debug_rfkill, new_value);
2798
+ trans_pcie->debug_rfkill = new_value;
27402799 iwl_pcie_handle_rfkill_irq(trans);
27412800
27422801 return count;
27432802 }
27442803
2804
+static int iwl_dbgfs_monitor_data_open(struct inode *inode,
2805
+ struct file *file)
2806
+{
2807
+ struct iwl_trans *trans = inode->i_private;
2808
+ struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2809
+
2810
+ if (!trans->dbg.dest_tlv ||
2811
+ trans->dbg.dest_tlv->monitor_mode != EXTERNAL_MODE) {
2812
+ IWL_ERR(trans, "Debug destination is not set to DRAM\n");
2813
+ return -ENOENT;
2814
+ }
2815
+
2816
+ if (trans_pcie->fw_mon_data.state != IWL_FW_MON_DBGFS_STATE_CLOSED)
2817
+ return -EBUSY;
2818
+
2819
+ trans_pcie->fw_mon_data.state = IWL_FW_MON_DBGFS_STATE_OPEN;
2820
+ return simple_open(inode, file);
2821
+}
2822
+
2823
+static int iwl_dbgfs_monitor_data_release(struct inode *inode,
2824
+ struct file *file)
2825
+{
2826
+ struct iwl_trans_pcie *trans_pcie =
2827
+ IWL_TRANS_GET_PCIE_TRANS(inode->i_private);
2828
+
2829
+ if (trans_pcie->fw_mon_data.state == IWL_FW_MON_DBGFS_STATE_OPEN)
2830
+ trans_pcie->fw_mon_data.state = IWL_FW_MON_DBGFS_STATE_CLOSED;
2831
+ return 0;
2832
+}
2833
+
2834
+static bool iwl_write_to_user_buf(char __user *user_buf, ssize_t count,
2835
+ void *buf, ssize_t *size,
2836
+ ssize_t *bytes_copied)
2837
+{
2838
+ ssize_t buf_size_left = count - *bytes_copied;
2839
+
2840
+ buf_size_left = buf_size_left - (buf_size_left % sizeof(u32));
2841
+ if (*size > buf_size_left)
2842
+ *size = buf_size_left;
2843
+
2844
+ *size -= copy_to_user(user_buf, buf, *size);
2845
+ *bytes_copied += *size;
2846
+
2847
+ if (buf_size_left == *size)
2848
+ return true;
2849
+ return false;
2850
+}
2851
+
2852
+static ssize_t iwl_dbgfs_monitor_data_read(struct file *file,
2853
+ char __user *user_buf,
2854
+ size_t count, loff_t *ppos)
2855
+{
2856
+ struct iwl_trans *trans = file->private_data;
2857
+ struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2858
+ void *cpu_addr = (void *)trans->dbg.fw_mon.block, *curr_buf;
2859
+ struct cont_rec *data = &trans_pcie->fw_mon_data;
2860
+ u32 write_ptr_addr, wrap_cnt_addr, write_ptr, wrap_cnt;
2861
+ ssize_t size, bytes_copied = 0;
2862
+ bool b_full;
2863
+
2864
+ if (trans->dbg.dest_tlv) {
2865
+ write_ptr_addr =
2866
+ le32_to_cpu(trans->dbg.dest_tlv->write_ptr_reg);
2867
+ wrap_cnt_addr = le32_to_cpu(trans->dbg.dest_tlv->wrap_count);
2868
+ } else {
2869
+ write_ptr_addr = MON_BUFF_WRPTR;
2870
+ wrap_cnt_addr = MON_BUFF_CYCLE_CNT;
2871
+ }
2872
+
2873
+ if (unlikely(!trans->dbg.rec_on))
2874
+ return 0;
2875
+
2876
+ mutex_lock(&data->mutex);
2877
+ if (data->state ==
2878
+ IWL_FW_MON_DBGFS_STATE_DISABLED) {
2879
+ mutex_unlock(&data->mutex);
2880
+ return 0;
2881
+ }
2882
+
2883
+ /* write_ptr position in bytes rather then DW */
2884
+ write_ptr = iwl_read_prph(trans, write_ptr_addr) * sizeof(u32);
2885
+ wrap_cnt = iwl_read_prph(trans, wrap_cnt_addr);
2886
+
2887
+ if (data->prev_wrap_cnt == wrap_cnt) {
2888
+ size = write_ptr - data->prev_wr_ptr;
2889
+ curr_buf = cpu_addr + data->prev_wr_ptr;
2890
+ b_full = iwl_write_to_user_buf(user_buf, count,
2891
+ curr_buf, &size,
2892
+ &bytes_copied);
2893
+ data->prev_wr_ptr += size;
2894
+
2895
+ } else if (data->prev_wrap_cnt == wrap_cnt - 1 &&
2896
+ write_ptr < data->prev_wr_ptr) {
2897
+ size = trans->dbg.fw_mon.size - data->prev_wr_ptr;
2898
+ curr_buf = cpu_addr + data->prev_wr_ptr;
2899
+ b_full = iwl_write_to_user_buf(user_buf, count,
2900
+ curr_buf, &size,
2901
+ &bytes_copied);
2902
+ data->prev_wr_ptr += size;
2903
+
2904
+ if (!b_full) {
2905
+ size = write_ptr;
2906
+ b_full = iwl_write_to_user_buf(user_buf, count,
2907
+ cpu_addr, &size,
2908
+ &bytes_copied);
2909
+ data->prev_wr_ptr = size;
2910
+ data->prev_wrap_cnt++;
2911
+ }
2912
+ } else {
2913
+ if (data->prev_wrap_cnt == wrap_cnt - 1 &&
2914
+ write_ptr > data->prev_wr_ptr)
2915
+ IWL_WARN(trans,
2916
+ "write pointer passed previous write pointer, start copying from the beginning\n");
2917
+ else if (!unlikely(data->prev_wrap_cnt == 0 &&
2918
+ data->prev_wr_ptr == 0))
2919
+ IWL_WARN(trans,
2920
+ "monitor data is out of sync, start copying from the beginning\n");
2921
+
2922
+ size = write_ptr;
2923
+ b_full = iwl_write_to_user_buf(user_buf, count,
2924
+ cpu_addr, &size,
2925
+ &bytes_copied);
2926
+ data->prev_wr_ptr = size;
2927
+ data->prev_wrap_cnt = wrap_cnt;
2928
+ }
2929
+
2930
+ mutex_unlock(&data->mutex);
2931
+
2932
+ return bytes_copied;
2933
+}
2934
+
27452935 DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
27462936 DEBUGFS_READ_FILE_OPS(fh_reg);
27472937 DEBUGFS_READ_FILE_OPS(rx_queue);
2748
-DEBUGFS_READ_FILE_OPS(tx_queue);
27492938 DEBUGFS_WRITE_FILE_OPS(csr);
27502939 DEBUGFS_READ_WRITE_FILE_OPS(rfkill);
2940
+static const struct file_operations iwl_dbgfs_tx_queue_ops = {
2941
+ .owner = THIS_MODULE,
2942
+ .open = iwl_dbgfs_tx_queue_open,
2943
+ .read = seq_read,
2944
+ .llseek = seq_lseek,
2945
+ .release = seq_release_private,
2946
+};
2947
+
2948
+static const struct file_operations iwl_dbgfs_monitor_data_ops = {
2949
+ .read = iwl_dbgfs_monitor_data_read,
2950
+ .open = iwl_dbgfs_monitor_data_open,
2951
+ .release = iwl_dbgfs_monitor_data_release,
2952
+};
27512953
27522954 /* Create the debugfs files and directories */
2753
-int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans)
2955
+void iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans)
27542956 {
27552957 struct dentry *dir = trans->dbgfs_dir;
27562958
....@@ -2760,22 +2962,27 @@
27602962 DEBUGFS_ADD_FILE(csr, dir, 0200);
27612963 DEBUGFS_ADD_FILE(fh_reg, dir, 0400);
27622964 DEBUGFS_ADD_FILE(rfkill, dir, 0600);
2763
- return 0;
2965
+ DEBUGFS_ADD_FILE(monitor_data, dir, 0400);
2966
+}
27642967
2765
-err:
2766
- IWL_ERR(trans, "failed to create the trans debugfs entry\n");
2767
- return -ENOMEM;
2968
+static void iwl_trans_pcie_debugfs_cleanup(struct iwl_trans *trans)
2969
+{
2970
+ struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2971
+ struct cont_rec *data = &trans_pcie->fw_mon_data;
2972
+
2973
+ mutex_lock(&data->mutex);
2974
+ data->state = IWL_FW_MON_DBGFS_STATE_DISABLED;
2975
+ mutex_unlock(&data->mutex);
27682976 }
27692977 #endif /*CONFIG_IWLWIFI_DEBUGFS */
27702978
27712979 static u32 iwl_trans_pcie_get_cmdlen(struct iwl_trans *trans, void *tfd)
27722980 {
2773
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
27742981 u32 cmdlen = 0;
27752982 int i;
27762983
2777
- for (i = 0; i < trans_pcie->max_tbs; i++)
2778
- cmdlen += iwl_pcie_tfd_tb_get_len(trans, tfd, i);
2984
+ for (i = 0; i < trans->txqs.tfd.max_tbs; i++)
2985
+ cmdlen += iwl_txq_gen1_tfd_tb_get_len(trans, tfd, i);
27792986
27802987 return cmdlen;
27812988 }
....@@ -2785,7 +2992,7 @@
27852992 int allocated_rb_nums)
27862993 {
27872994 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2788
- int max_len = PAGE_SIZE << trans_pcie->rx_page_order;
2995
+ int max_len = trans_pcie->rx_buf_bytes;
27892996 /* Dump RBs is supported only for pre-9000 devices (1 queue) */
27902997 struct iwl_rxq *rxq = &trans_pcie->rxq[0];
27912998 u32 i, r, j, rb_len = 0;
....@@ -2811,9 +3018,9 @@
28113018 rb->index = cpu_to_le32(i);
28123019 memcpy(rb->data, page_address(rxb->page), max_len);
28133020 /* remap the page for the free benefit */
2814
- rxb->page_dma = dma_map_page(trans->dev, rxb->page, 0,
2815
- max_len,
2816
- DMA_FROM_DEVICE);
3021
+ rxb->page_dma = dma_map_page(trans->dev, rxb->page,
3022
+ rxb->offset, max_len,
3023
+ DMA_FROM_DEVICE);
28173024
28183025 *data = iwl_fw_error_next_data(*data);
28193026 }
....@@ -2858,12 +3065,13 @@
28583065 (*data)->len = cpu_to_le32(fh_regs_len);
28593066 val = (void *)(*data)->data;
28603067
2861
- if (!trans->cfg->gen2)
3068
+ if (!trans->trans_cfg->gen2)
28623069 for (i = FH_MEM_LOWER_BOUND; i < FH_MEM_UPPER_BOUND;
28633070 i += sizeof(u32))
28643071 *val++ = cpu_to_le32(iwl_trans_pcie_read32(trans, i));
28653072 else
2866
- for (i = FH_MEM_LOWER_BOUND_GEN2; i < FH_MEM_UPPER_BOUND_GEN2;
3073
+ for (i = iwl_umac_prph(trans, FH_MEM_LOWER_BOUND_GEN2);
3074
+ i < iwl_umac_prph(trans, FH_MEM_UPPER_BOUND_GEN2);
28673075 i += sizeof(u32))
28683076 *val++ = cpu_to_le32(iwl_trans_pcie_read_prph(trans,
28693077 i));
....@@ -2888,15 +3096,49 @@
28883096 if (!iwl_trans_grab_nic_access(trans, &flags))
28893097 return 0;
28903098
2891
- iwl_write_prph_no_grab(trans, MON_DMARB_RD_CTL_ADDR, 0x1);
3099
+ iwl_write_umac_prph_no_grab(trans, MON_DMARB_RD_CTL_ADDR, 0x1);
28923100 for (i = 0; i < buf_size_in_dwords; i++)
2893
- buffer[i] = iwl_read_prph_no_grab(trans,
2894
- MON_DMARB_RD_DATA_ADDR);
2895
- iwl_write_prph_no_grab(trans, MON_DMARB_RD_CTL_ADDR, 0x0);
3101
+ buffer[i] = iwl_read_umac_prph_no_grab(trans,
3102
+ MON_DMARB_RD_DATA_ADDR);
3103
+ iwl_write_umac_prph_no_grab(trans, MON_DMARB_RD_CTL_ADDR, 0x0);
28963104
28973105 iwl_trans_release_nic_access(trans, &flags);
28983106
28993107 return monitor_len;
3108
+}
3109
+
3110
+static void
3111
+iwl_trans_pcie_dump_pointers(struct iwl_trans *trans,
3112
+ struct iwl_fw_error_dump_fw_mon *fw_mon_data)
3113
+{
3114
+ u32 base, base_high, write_ptr, write_ptr_val, wrap_cnt;
3115
+
3116
+ if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
3117
+ base = DBGC_CUR_DBGBUF_BASE_ADDR_LSB;
3118
+ base_high = DBGC_CUR_DBGBUF_BASE_ADDR_MSB;
3119
+ write_ptr = DBGC_CUR_DBGBUF_STATUS;
3120
+ wrap_cnt = DBGC_DBGBUF_WRAP_AROUND;
3121
+ } else if (trans->dbg.dest_tlv) {
3122
+ write_ptr = le32_to_cpu(trans->dbg.dest_tlv->write_ptr_reg);
3123
+ wrap_cnt = le32_to_cpu(trans->dbg.dest_tlv->wrap_count);
3124
+ base = le32_to_cpu(trans->dbg.dest_tlv->base_reg);
3125
+ } else {
3126
+ base = MON_BUFF_BASE_ADDR;
3127
+ write_ptr = MON_BUFF_WRPTR;
3128
+ wrap_cnt = MON_BUFF_CYCLE_CNT;
3129
+ }
3130
+
3131
+ write_ptr_val = iwl_read_prph(trans, write_ptr);
3132
+ fw_mon_data->fw_mon_cycle_cnt =
3133
+ cpu_to_le32(iwl_read_prph(trans, wrap_cnt));
3134
+ fw_mon_data->fw_mon_base_ptr =
3135
+ cpu_to_le32(iwl_read_prph(trans, base));
3136
+ if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
3137
+ fw_mon_data->fw_mon_base_high_ptr =
3138
+ cpu_to_le32(iwl_read_prph(trans, base_high));
3139
+ write_ptr_val &= DBGC_CUR_DBGBUF_STATUS_OFFSET_MSK;
3140
+ }
3141
+ fw_mon_data->fw_mon_wr_ptr = cpu_to_le32(write_ptr_val);
29003142 }
29013143
29023144 static u32
....@@ -2904,72 +3146,44 @@
29043146 struct iwl_fw_error_dump_data **data,
29053147 u32 monitor_len)
29063148 {
2907
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
3149
+ struct iwl_dram_data *fw_mon = &trans->dbg.fw_mon;
29083150 u32 len = 0;
29093151
2910
- if ((trans_pcie->fw_mon_page &&
2911
- trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) ||
2912
- trans->dbg_dest_tlv) {
3152
+ if (trans->dbg.dest_tlv ||
3153
+ (fw_mon->size &&
3154
+ (trans->trans_cfg->device_family == IWL_DEVICE_FAMILY_7000 ||
3155
+ trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210))) {
29133156 struct iwl_fw_error_dump_fw_mon *fw_mon_data;
2914
- u32 base, write_ptr, wrap_cnt;
2915
-
2916
- /* If there was a dest TLV - use the values from there */
2917
- if (trans->dbg_dest_tlv) {
2918
- write_ptr =
2919
- le32_to_cpu(trans->dbg_dest_tlv->write_ptr_reg);
2920
- wrap_cnt = le32_to_cpu(trans->dbg_dest_tlv->wrap_count);
2921
- base = le32_to_cpu(trans->dbg_dest_tlv->base_reg);
2922
- } else {
2923
- base = MON_BUFF_BASE_ADDR;
2924
- write_ptr = MON_BUFF_WRPTR;
2925
- wrap_cnt = MON_BUFF_CYCLE_CNT;
2926
- }
29273157
29283158 (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_FW_MONITOR);
29293159 fw_mon_data = (void *)(*data)->data;
2930
- fw_mon_data->fw_mon_wr_ptr =
2931
- cpu_to_le32(iwl_read_prph(trans, write_ptr));
2932
- fw_mon_data->fw_mon_cycle_cnt =
2933
- cpu_to_le32(iwl_read_prph(trans, wrap_cnt));
2934
- fw_mon_data->fw_mon_base_ptr =
2935
- cpu_to_le32(iwl_read_prph(trans, base));
3160
+
3161
+ iwl_trans_pcie_dump_pointers(trans, fw_mon_data);
29363162
29373163 len += sizeof(**data) + sizeof(*fw_mon_data);
2938
- if (trans_pcie->fw_mon_page) {
2939
- /*
2940
- * The firmware is now asserted, it won't write anything
2941
- * to the buffer. CPU can take ownership to fetch the
2942
- * data. The buffer will be handed back to the device
2943
- * before the firmware will be restarted.
2944
- */
2945
- dma_sync_single_for_cpu(trans->dev,
2946
- trans_pcie->fw_mon_phys,
2947
- trans_pcie->fw_mon_size,
2948
- DMA_FROM_DEVICE);
2949
- memcpy(fw_mon_data->data,
2950
- page_address(trans_pcie->fw_mon_page),
2951
- trans_pcie->fw_mon_size);
2952
-
2953
- monitor_len = trans_pcie->fw_mon_size;
2954
- } else if (trans->dbg_dest_tlv->monitor_mode == SMEM_MODE) {
3164
+ if (fw_mon->size) {
3165
+ memcpy(fw_mon_data->data, fw_mon->block, fw_mon->size);
3166
+ monitor_len = fw_mon->size;
3167
+ } else if (trans->dbg.dest_tlv->monitor_mode == SMEM_MODE) {
3168
+ u32 base = le32_to_cpu(fw_mon_data->fw_mon_base_ptr);
29553169 /*
29563170 * Update pointers to reflect actual values after
29573171 * shifting
29583172 */
2959
- if (trans->dbg_dest_tlv->version) {
3173
+ if (trans->dbg.dest_tlv->version) {
29603174 base = (iwl_read_prph(trans, base) &
29613175 IWL_LDBG_M2S_BUF_BA_MSK) <<
2962
- trans->dbg_dest_tlv->base_shift;
3176
+ trans->dbg.dest_tlv->base_shift;
29633177 base *= IWL_M2S_UNIT_SIZE;
29643178 base += trans->cfg->smem_offset;
29653179 } else {
29663180 base = iwl_read_prph(trans, base) <<
2967
- trans->dbg_dest_tlv->base_shift;
3181
+ trans->dbg.dest_tlv->base_shift;
29683182 }
29693183
29703184 iwl_trans_read_mem(trans, base, fw_mon_data->data,
29713185 monitor_len / sizeof(u32));
2972
- } else if (trans->dbg_dest_tlv->monitor_mode == MARBH_MODE) {
3186
+ } else if (trans->dbg.dest_tlv->monitor_mode == MARBH_MODE) {
29733187 monitor_len =
29743188 iwl_trans_pci_dump_marbh_monitor(trans,
29753189 fw_mon_data,
....@@ -2986,97 +3200,93 @@
29863200 return len;
29873201 }
29883202
2989
-static struct iwl_trans_dump_data
2990
-*iwl_trans_pcie_dump_data(struct iwl_trans *trans,
2991
- const struct iwl_fw_dbg_trigger_tlv *trigger)
3203
+static int iwl_trans_get_fw_monitor_len(struct iwl_trans *trans, u32 *len)
29923204 {
2993
- struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2994
- struct iwl_fw_error_dump_data *data;
2995
- struct iwl_txq *cmdq = trans_pcie->txq[trans_pcie->cmd_queue];
2996
- struct iwl_fw_error_dump_txcmd *txcmd;
2997
- struct iwl_trans_dump_data *dump_data;
2998
- u32 len, num_rbs = 0;
2999
- u32 monitor_len;
3000
- int i, ptr;
3001
- bool dump_rbs = test_bit(STATUS_FW_ERROR, &trans->status) &&
3002
- !trans->cfg->mq_rx_supported &&
3003
- trans->dbg_dump_mask & BIT(IWL_FW_ERROR_DUMP_RB);
3205
+ if (trans->dbg.fw_mon.size) {
3206
+ *len += sizeof(struct iwl_fw_error_dump_data) +
3207
+ sizeof(struct iwl_fw_error_dump_fw_mon) +
3208
+ trans->dbg.fw_mon.size;
3209
+ return trans->dbg.fw_mon.size;
3210
+ } else if (trans->dbg.dest_tlv) {
3211
+ u32 base, end, cfg_reg, monitor_len;
30043212
3005
- /* transport dump header */
3006
- len = sizeof(*dump_data);
3007
-
3008
- /* host commands */
3009
- len += sizeof(*data) +
3010
- cmdq->n_window * (sizeof(*txcmd) + TFD_MAX_PAYLOAD_SIZE);
3011
-
3012
- /* FW monitor */
3013
- if (trans_pcie->fw_mon_page) {
3014
- len += sizeof(*data) + sizeof(struct iwl_fw_error_dump_fw_mon) +
3015
- trans_pcie->fw_mon_size;
3016
- monitor_len = trans_pcie->fw_mon_size;
3017
- } else if (trans->dbg_dest_tlv) {
3018
- u32 base, end, cfg_reg;
3019
-
3020
- if (trans->dbg_dest_tlv->version == 1) {
3021
- cfg_reg = le32_to_cpu(trans->dbg_dest_tlv->base_reg);
3213
+ if (trans->dbg.dest_tlv->version == 1) {
3214
+ cfg_reg = le32_to_cpu(trans->dbg.dest_tlv->base_reg);
30223215 cfg_reg = iwl_read_prph(trans, cfg_reg);
30233216 base = (cfg_reg & IWL_LDBG_M2S_BUF_BA_MSK) <<
3024
- trans->dbg_dest_tlv->base_shift;
3217
+ trans->dbg.dest_tlv->base_shift;
30253218 base *= IWL_M2S_UNIT_SIZE;
30263219 base += trans->cfg->smem_offset;
30273220
30283221 monitor_len =
30293222 (cfg_reg & IWL_LDBG_M2S_BUF_SIZE_MSK) >>
3030
- trans->dbg_dest_tlv->end_shift;
3223
+ trans->dbg.dest_tlv->end_shift;
30313224 monitor_len *= IWL_M2S_UNIT_SIZE;
30323225 } else {
3033
- base = le32_to_cpu(trans->dbg_dest_tlv->base_reg);
3034
- end = le32_to_cpu(trans->dbg_dest_tlv->end_reg);
3226
+ base = le32_to_cpu(trans->dbg.dest_tlv->base_reg);
3227
+ end = le32_to_cpu(trans->dbg.dest_tlv->end_reg);
30353228
30363229 base = iwl_read_prph(trans, base) <<
3037
- trans->dbg_dest_tlv->base_shift;
3230
+ trans->dbg.dest_tlv->base_shift;
30383231 end = iwl_read_prph(trans, end) <<
3039
- trans->dbg_dest_tlv->end_shift;
3232
+ trans->dbg.dest_tlv->end_shift;
30403233
30413234 /* Make "end" point to the actual end */
3042
- if (trans->cfg->device_family >=
3235
+ if (trans->trans_cfg->device_family >=
30433236 IWL_DEVICE_FAMILY_8000 ||
3044
- trans->dbg_dest_tlv->monitor_mode == MARBH_MODE)
3045
- end += (1 << trans->dbg_dest_tlv->end_shift);
3237
+ trans->dbg.dest_tlv->monitor_mode == MARBH_MODE)
3238
+ end += (1 << trans->dbg.dest_tlv->end_shift);
30463239 monitor_len = end - base;
30473240 }
3048
- len += sizeof(*data) + sizeof(struct iwl_fw_error_dump_fw_mon) +
3049
- monitor_len;
3050
- } else {
3051
- monitor_len = 0;
3241
+ *len += sizeof(struct iwl_fw_error_dump_data) +
3242
+ sizeof(struct iwl_fw_error_dump_fw_mon) +
3243
+ monitor_len;
3244
+ return monitor_len;
30523245 }
3246
+ return 0;
3247
+}
30533248
3054
- if (trigger && (trigger->mode & IWL_FW_DBG_TRIGGER_MONITOR_ONLY)) {
3055
- if (!(trans->dbg_dump_mask &
3056
- BIT(IWL_FW_ERROR_DUMP_FW_MONITOR)))
3057
- return NULL;
3249
+static struct iwl_trans_dump_data
3250
+*iwl_trans_pcie_dump_data(struct iwl_trans *trans,
3251
+ u32 dump_mask)
3252
+{
3253
+ struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
3254
+ struct iwl_fw_error_dump_data *data;
3255
+ struct iwl_txq *cmdq = trans->txqs.txq[trans->txqs.cmd.q_id];
3256
+ struct iwl_fw_error_dump_txcmd *txcmd;
3257
+ struct iwl_trans_dump_data *dump_data;
3258
+ u32 len, num_rbs = 0, monitor_len = 0;
3259
+ int i, ptr;
3260
+ bool dump_rbs = test_bit(STATUS_FW_ERROR, &trans->status) &&
3261
+ !trans->trans_cfg->mq_rx_supported &&
3262
+ dump_mask & BIT(IWL_FW_ERROR_DUMP_RB);
30583263
3059
- dump_data = vzalloc(len);
3060
- if (!dump_data)
3061
- return NULL;
3264
+ if (!dump_mask)
3265
+ return NULL;
30623266
3063
- data = (void *)dump_data->data;
3064
- len = iwl_trans_pcie_dump_monitor(trans, &data, monitor_len);
3065
- dump_data->len = len;
3267
+ /* transport dump header */
3268
+ len = sizeof(*dump_data);
30663269
3067
- return dump_data;
3068
- }
3270
+ /* host commands */
3271
+ if (dump_mask & BIT(IWL_FW_ERROR_DUMP_TXCMD) && cmdq)
3272
+ len += sizeof(*data) +
3273
+ cmdq->n_window * (sizeof(*txcmd) +
3274
+ TFD_MAX_PAYLOAD_SIZE);
3275
+
3276
+ /* FW monitor */
3277
+ if (dump_mask & BIT(IWL_FW_ERROR_DUMP_FW_MONITOR))
3278
+ monitor_len = iwl_trans_get_fw_monitor_len(trans, &len);
30693279
30703280 /* CSR registers */
3071
- if (trans->dbg_dump_mask & BIT(IWL_FW_ERROR_DUMP_CSR))
3281
+ if (dump_mask & BIT(IWL_FW_ERROR_DUMP_CSR))
30723282 len += sizeof(*data) + IWL_CSR_TO_DUMP;
30733283
30743284 /* FH registers */
3075
- if (trans->dbg_dump_mask & BIT(IWL_FW_ERROR_DUMP_FH_REGS)) {
3076
- if (trans->cfg->gen2)
3285
+ if (dump_mask & BIT(IWL_FW_ERROR_DUMP_FH_REGS)) {
3286
+ if (trans->trans_cfg->gen2)
30773287 len += sizeof(*data) +
3078
- (FH_MEM_UPPER_BOUND_GEN2 -
3079
- FH_MEM_LOWER_BOUND_GEN2);
3288
+ (iwl_umac_prph(trans, FH_MEM_UPPER_BOUND_GEN2) -
3289
+ iwl_umac_prph(trans, FH_MEM_LOWER_BOUND_GEN2));
30803290 else
30813291 len += sizeof(*data) +
30823292 (FH_MEM_UPPER_BOUND -
....@@ -3097,12 +3307,11 @@
30973307 }
30983308
30993309 /* Paged memory for gen2 HW */
3100
- if (trans->cfg->gen2 &&
3101
- trans->dbg_dump_mask & BIT(IWL_FW_ERROR_DUMP_PAGING))
3102
- for (i = 0; i < trans_pcie->init_dram.paging_cnt; i++)
3310
+ if (trans->trans_cfg->gen2 && dump_mask & BIT(IWL_FW_ERROR_DUMP_PAGING))
3311
+ for (i = 0; i < trans->init_dram.paging_cnt; i++)
31033312 len += sizeof(*data) +
31043313 sizeof(struct iwl_fw_error_dump_paging) +
3105
- trans_pcie->init_dram.paging[i].size;
3314
+ trans->init_dram.paging[i].size;
31063315
31073316 dump_data = vzalloc(len);
31083317 if (!dump_data)
....@@ -3111,20 +3320,26 @@
31113320 len = 0;
31123321 data = (void *)dump_data->data;
31133322
3114
- if (trans->dbg_dump_mask & BIT(IWL_FW_ERROR_DUMP_TXCMD)) {
3115
- u16 tfd_size = trans_pcie->tfd_size;
3323
+ if (dump_mask & BIT(IWL_FW_ERROR_DUMP_TXCMD) && cmdq) {
3324
+ u16 tfd_size = trans->txqs.tfd.size;
31163325
31173326 data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXCMD);
31183327 txcmd = (void *)data->data;
31193328 spin_lock_bh(&cmdq->lock);
31203329 ptr = cmdq->write_ptr;
31213330 for (i = 0; i < cmdq->n_window; i++) {
3122
- u8 idx = iwl_pcie_get_cmd_index(cmdq, ptr);
3331
+ u8 idx = iwl_txq_get_cmd_index(cmdq, ptr);
3332
+ u8 tfdidx;
31233333 u32 caplen, cmdlen;
31243334
3335
+ if (trans->trans_cfg->use_tfh)
3336
+ tfdidx = idx;
3337
+ else
3338
+ tfdidx = ptr;
3339
+
31253340 cmdlen = iwl_trans_pcie_get_cmdlen(trans,
3126
- cmdq->tfds +
3127
- tfd_size * ptr);
3341
+ (u8 *)cmdq->tfds +
3342
+ tfd_size * tfdidx);
31283343 caplen = min_t(u32, TFD_MAX_PAYLOAD_SIZE, cmdlen);
31293344
31303345 if (cmdlen) {
....@@ -3136,7 +3351,7 @@
31363351 txcmd = (void *)((u8 *)txcmd->data + caplen);
31373352 }
31383353
3139
- ptr = iwl_queue_dec_wrap(trans, ptr);
3354
+ ptr = iwl_txq_dec_wrap(trans, ptr);
31403355 }
31413356 spin_unlock_bh(&cmdq->lock);
31423357
....@@ -3145,36 +3360,32 @@
31453360 data = iwl_fw_error_next_data(data);
31463361 }
31473362
3148
- if (trans->dbg_dump_mask & BIT(IWL_FW_ERROR_DUMP_CSR))
3363
+ if (dump_mask & BIT(IWL_FW_ERROR_DUMP_CSR))
31493364 len += iwl_trans_pcie_dump_csr(trans, &data);
3150
- if (trans->dbg_dump_mask & BIT(IWL_FW_ERROR_DUMP_FH_REGS))
3365
+ if (dump_mask & BIT(IWL_FW_ERROR_DUMP_FH_REGS))
31513366 len += iwl_trans_pcie_fh_regs_dump(trans, &data);
31523367 if (dump_rbs)
31533368 len += iwl_trans_pcie_dump_rbs(trans, &data, num_rbs);
31543369
31553370 /* Paged memory for gen2 HW */
3156
- if (trans->cfg->gen2 &&
3157
- trans->dbg_dump_mask & BIT(IWL_FW_ERROR_DUMP_PAGING)) {
3158
- for (i = 0; i < trans_pcie->init_dram.paging_cnt; i++) {
3371
+ if (trans->trans_cfg->gen2 &&
3372
+ dump_mask & BIT(IWL_FW_ERROR_DUMP_PAGING)) {
3373
+ for (i = 0; i < trans->init_dram.paging_cnt; i++) {
31593374 struct iwl_fw_error_dump_paging *paging;
3160
- dma_addr_t addr =
3161
- trans_pcie->init_dram.paging[i].physical;
3162
- u32 page_len = trans_pcie->init_dram.paging[i].size;
3375
+ u32 page_len = trans->init_dram.paging[i].size;
31633376
31643377 data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PAGING);
31653378 data->len = cpu_to_le32(sizeof(*paging) + page_len);
31663379 paging = (void *)data->data;
31673380 paging->index = cpu_to_le32(i);
3168
- dma_sync_single_for_cpu(trans->dev, addr, page_len,
3169
- DMA_BIDIRECTIONAL);
31703381 memcpy(paging->data,
3171
- trans_pcie->init_dram.paging[i].block, page_len);
3382
+ trans->init_dram.paging[i].block, page_len);
31723383 data = iwl_fw_error_next_data(data);
31733384
31743385 len += sizeof(*data) + sizeof(*paging) + page_len;
31753386 }
31763387 }
3177
- if (trans->dbg_dump_mask & BIT(IWL_FW_ERROR_DUMP_FW_MONITOR))
3388
+ if (dump_mask & BIT(IWL_FW_ERROR_DUMP_FW_MONITOR))
31783389 len += iwl_trans_pcie_dump_monitor(trans, &data, monitor_len);
31793390
31803391 dump_data->len = len;
....@@ -3185,18 +3396,11 @@
31853396 #ifdef CONFIG_PM_SLEEP
31863397 static int iwl_trans_pcie_suspend(struct iwl_trans *trans)
31873398 {
3188
- if (trans->runtime_pm_mode == IWL_PLAT_PM_MODE_D0I3 &&
3189
- (trans->system_pm_mode == IWL_PLAT_PM_MODE_D0I3))
3190
- return iwl_pci_fw_enter_d0i3(trans);
3191
-
31923399 return 0;
31933400 }
31943401
31953402 static void iwl_trans_pcie_resume(struct iwl_trans *trans)
31963403 {
3197
- if (trans->runtime_pm_mode == IWL_PLAT_PM_MODE_D0I3 &&
3198
- (trans->system_pm_mode == IWL_PLAT_PM_MODE_D0I3))
3199
- iwl_pci_fw_exit_d0i3(trans);
32003404 }
32013405 #endif /* CONFIG_PM_SLEEP */
32023406
....@@ -3209,18 +3413,17 @@
32093413 .write_prph = iwl_trans_pcie_write_prph, \
32103414 .read_mem = iwl_trans_pcie_read_mem, \
32113415 .write_mem = iwl_trans_pcie_write_mem, \
3416
+ .read_config32 = iwl_trans_pcie_read_config32, \
32123417 .configure = iwl_trans_pcie_configure, \
32133418 .set_pmi = iwl_trans_pcie_set_pmi, \
32143419 .sw_reset = iwl_trans_pcie_sw_reset, \
32153420 .grab_nic_access = iwl_trans_pcie_grab_nic_access, \
32163421 .release_nic_access = iwl_trans_pcie_release_nic_access, \
32173422 .set_bits_mask = iwl_trans_pcie_set_bits_mask, \
3218
- .ref = iwl_trans_pcie_ref, \
3219
- .unref = iwl_trans_pcie_unref, \
32203423 .dump_data = iwl_trans_pcie_dump_data, \
3221
- .dump_regs = iwl_trans_pcie_dump_regs, \
32223424 .d3_suspend = iwl_trans_pcie_d3_suspend, \
3223
- .d3_resume = iwl_trans_pcie_d3_resume
3425
+ .d3_resume = iwl_trans_pcie_d3_resume, \
3426
+ .sync_nmi = iwl_trans_pcie_sync_nmi
32243427
32253428 #ifdef CONFIG_PM_SLEEP
32263429 #define IWL_TRANS_PM_OPS \
....@@ -3252,6 +3455,9 @@
32523455
32533456 .freeze_txq_timer = iwl_trans_pcie_freeze_txq_timer,
32543457 .block_txq_ptrs = iwl_trans_pcie_block_txq_ptrs,
3458
+#ifdef CONFIG_IWLWIFI_DEBUGFS
3459
+ .debugfs_cleanup = iwl_trans_pcie_debugfs_cleanup,
3460
+#endif
32553461 };
32563462
32573463 static const struct iwl_trans_ops trans_ops_pcie_gen2 = {
....@@ -3264,33 +3470,39 @@
32643470
32653471 .send_cmd = iwl_trans_pcie_gen2_send_hcmd,
32663472
3267
- .tx = iwl_trans_pcie_gen2_tx,
3473
+ .tx = iwl_txq_gen2_tx,
32683474 .reclaim = iwl_trans_pcie_reclaim,
32693475
3270
- .txq_alloc = iwl_trans_pcie_dyn_txq_alloc,
3271
- .txq_free = iwl_trans_pcie_dyn_txq_free,
3476
+ .set_q_ptrs = iwl_trans_pcie_set_q_ptrs,
3477
+
3478
+ .txq_alloc = iwl_txq_dyn_alloc,
3479
+ .txq_free = iwl_txq_dyn_free,
32723480 .wait_txq_empty = iwl_trans_pcie_wait_txq_empty,
32733481 .rxq_dma_data = iwl_trans_pcie_rxq_dma_data,
3482
+ .set_pnvm = iwl_trans_pcie_ctx_info_gen3_set_pnvm,
3483
+#ifdef CONFIG_IWLWIFI_DEBUGFS
3484
+ .debugfs_cleanup = iwl_trans_pcie_debugfs_cleanup,
3485
+#endif
32743486 };
32753487
32763488 struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
3277
- const struct pci_device_id *ent,
3278
- const struct iwl_cfg *cfg)
3489
+ const struct pci_device_id *ent,
3490
+ const struct iwl_cfg_trans_params *cfg_trans)
32793491 {
32803492 struct iwl_trans_pcie *trans_pcie;
32813493 struct iwl_trans *trans;
32823494 int ret, addr_size;
3495
+ const struct iwl_trans_ops *ops = &trans_ops_pcie_gen2;
3496
+
3497
+ if (!cfg_trans->gen2)
3498
+ ops = &trans_ops_pcie;
32833499
32843500 ret = pcim_enable_device(pdev);
32853501 if (ret)
32863502 return ERR_PTR(ret);
32873503
3288
- if (cfg->gen2)
3289
- trans = iwl_trans_alloc(sizeof(struct iwl_trans_pcie),
3290
- &pdev->dev, cfg, &trans_ops_pcie_gen2);
3291
- else
3292
- trans = iwl_trans_alloc(sizeof(struct iwl_trans_pcie),
3293
- &pdev->dev, cfg, &trans_ops_pcie);
3504
+ trans = iwl_trans_alloc(sizeof(struct iwl_trans_pcie), &pdev->dev, ops,
3505
+ cfg_trans);
32943506 if (!trans)
32953507 return ERR_PTR(-ENOMEM);
32963508
....@@ -3300,6 +3512,7 @@
33003512 trans_pcie->opmode_down = true;
33013513 spin_lock_init(&trans_pcie->irq_lock);
33023514 spin_lock_init(&trans_pcie->reg_lock);
3515
+ spin_lock_init(&trans_pcie->alloc_page_lock);
33033516 mutex_init(&trans_pcie->mutex);
33043517 init_waitqueue_head(&trans_pcie->ucode_write_waitq);
33053518
....@@ -3311,14 +3524,9 @@
33113524 }
33123525 INIT_WORK(&trans_pcie->rba.rx_alloc, iwl_pcie_rx_allocator_work);
33133526
3314
- trans_pcie->tso_hdr_page = alloc_percpu(struct iwl_tso_hdr_page);
3315
- if (!trans_pcie->tso_hdr_page) {
3316
- ret = -ENOMEM;
3317
- goto out_no_pci;
3318
- }
3527
+ trans_pcie->debug_rfkill = -1;
33193528
3320
-
3321
- if (!cfg->base_params->pcie_l1_allowed) {
3529
+ if (!cfg_trans->base_params->pcie_l1_allowed) {
33223530 /*
33233531 * W/A - seems to solve weird behavior. We need to remove this
33243532 * if we don't want to stay in L1 all the time. This wastes a
....@@ -3329,19 +3537,11 @@
33293537 PCIE_LINK_STATE_CLKPM);
33303538 }
33313539
3332
- if (cfg->use_tfh) {
3333
- addr_size = 64;
3334
- trans_pcie->max_tbs = IWL_TFH_NUM_TBS;
3335
- trans_pcie->tfd_size = sizeof(struct iwl_tfh_tfd);
3336
- } else {
3337
- addr_size = 36;
3338
- trans_pcie->max_tbs = IWL_NUM_OF_TBS;
3339
- trans_pcie->tfd_size = sizeof(struct iwl_tfd);
3340
- }
3341
- trans->max_skb_frags = IWL_PCIE_MAX_FRAGS(trans_pcie);
3540
+ trans_pcie->def_rx_queue = 0;
33423541
33433542 pci_set_master(pdev);
33443543
3544
+ addr_size = trans->txqs.tfd.addr_size;
33453545 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(addr_size));
33463546 if (!ret)
33473547 ret = pci_set_consistent_dma_mask(pdev,
....@@ -3379,15 +3579,19 @@
33793579 iwl_disable_interrupts(trans);
33803580
33813581 trans->hw_rev = iwl_read32(trans, CSR_HW_REV);
3582
+ if (trans->hw_rev == 0xffffffff) {
3583
+ dev_err(&pdev->dev, "HW_REV=0xFFFFFFFF, PCI issues?\n");
3584
+ ret = -EIO;
3585
+ goto out_no_pci;
3586
+ }
3587
+
33823588 /*
33833589 * In the 8000 HW family the format of the 4 bytes of CSR_HW_REV have
33843590 * changed, and now the revision step also includes bit 0-1 (no more
33853591 * "dash" value). To keep hw_rev backwards compatible - we'll store it
33863592 * in the old format.
33873593 */
3388
- if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000) {
3389
- unsigned long flags;
3390
-
3594
+ if (cfg_trans->device_family >= IWL_DEVICE_FAMILY_8000) {
33913595 trans->hw_rev = (trans->hw_rev & 0xfff0) |
33923596 (CSR_HW_REV_STEP(trans->hw_rev << 2) << 2);
33933597
....@@ -3401,89 +3605,15 @@
34013605 * in-order to recognize C step driver should read chip version
34023606 * id located at the AUX bus MISC address space.
34033607 */
3404
- iwl_set_bit(trans, CSR_GP_CNTRL,
3405
- BIT(trans->cfg->csr->flag_init_done));
3406
- udelay(2);
3407
-
3408
- ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
3409
- BIT(trans->cfg->csr->flag_mac_clock_ready),
3410
- BIT(trans->cfg->csr->flag_mac_clock_ready),
3411
- 25000);
3412
- if (ret < 0) {
3413
- IWL_DEBUG_INFO(trans, "Failed to wake up the nic\n");
3608
+ ret = iwl_finish_nic_init(trans, cfg_trans);
3609
+ if (ret)
34143610 goto out_no_pci;
3415
- }
34163611
3417
- if (iwl_trans_grab_nic_access(trans, &flags)) {
3418
- u32 hw_step;
3419
-
3420
- hw_step = iwl_read_prph_no_grab(trans, WFPM_CTRL_REG);
3421
- hw_step |= ENABLE_WFPM;
3422
- iwl_write_prph_no_grab(trans, WFPM_CTRL_REG, hw_step);
3423
- hw_step = iwl_read_prph_no_grab(trans, AUX_MISC_REG);
3424
- hw_step = (hw_step >> HW_STEP_LOCATION_BITS) & 0xF;
3425
- if (hw_step == 0x3)
3426
- trans->hw_rev = (trans->hw_rev & 0xFFFFFFF3) |
3427
- (SILICON_C_STEP << 2);
3428
- iwl_trans_release_nic_access(trans, &flags);
3429
- }
34303612 }
34313613
3432
- /*
3433
- * 9000-series integrated A-step has a problem with suspend/resume
3434
- * and sometimes even causes the whole platform to get stuck. This
3435
- * workaround makes the hardware not go into the problematic state.
3436
- */
3437
- if (trans->cfg->integrated &&
3438
- trans->cfg->device_family == IWL_DEVICE_FAMILY_9000 &&
3439
- CSR_HW_REV_STEP(trans->hw_rev) == SILICON_A_STEP)
3440
- iwl_set_bit(trans, CSR_HOST_CHICKEN,
3441
- CSR_HOST_CHICKEN_PM_IDLE_SRC_DIS_SB_PME);
3614
+ IWL_DEBUG_INFO(trans, "HW REV: 0x%0x\n", trans->hw_rev);
34423615
3443
-#if IS_ENABLED(CONFIG_IWLMVM)
3444
- trans->hw_rf_id = iwl_read32(trans, CSR_HW_RF_ID);
3445
-
3446
- if (cfg == &iwl22000_2ax_cfg_hr) {
3447
- if (CSR_HW_RF_ID_TYPE_CHIP_ID(trans->hw_rf_id) ==
3448
- CSR_HW_RF_ID_TYPE_CHIP_ID(CSR_HW_RF_ID_TYPE_HR)) {
3449
- trans->cfg = &iwl22000_2ax_cfg_hr;
3450
- } else if (CSR_HW_RF_ID_TYPE_CHIP_ID(trans->hw_rf_id) ==
3451
- CSR_HW_RF_ID_TYPE_CHIP_ID(CSR_HW_RF_ID_TYPE_JF)) {
3452
- trans->cfg = &iwl22000_2ax_cfg_jf;
3453
- } else if (CSR_HW_RF_ID_TYPE_CHIP_ID(trans->hw_rf_id) ==
3454
- CSR_HW_RF_ID_TYPE_CHIP_ID(CSR_HW_RF_ID_TYPE_HRCDB)) {
3455
- IWL_ERR(trans, "RF ID HRCDB is not supported\n");
3456
- ret = -EINVAL;
3457
- goto out_no_pci;
3458
- } else {
3459
- IWL_ERR(trans, "Unrecognized RF ID 0x%08x\n",
3460
- CSR_HW_RF_ID_TYPE_CHIP_ID(trans->hw_rf_id));
3461
- ret = -EINVAL;
3462
- goto out_no_pci;
3463
- }
3464
- } else if (CSR_HW_RF_ID_TYPE_CHIP_ID(trans->hw_rf_id) ==
3465
- CSR_HW_RF_ID_TYPE_CHIP_ID(CSR_HW_RF_ID_TYPE_HR)) {
3466
- u32 hw_status;
3467
-
3468
- hw_status = iwl_read_prph(trans, UMAG_GEN_HW_STATUS);
3469
- if (CSR_HW_RF_STEP(trans->hw_rf_id) == SILICON_B_STEP)
3470
- /*
3471
- * b step fw is the same for physical card and fpga
3472
- */
3473
- trans->cfg = &iwl22000_2ax_cfg_qnj_hr_b0;
3474
- else if ((hw_status & UMAG_GEN_HW_IS_FPGA) &&
3475
- CSR_HW_RF_STEP(trans->hw_rf_id) == SILICON_A_STEP) {
3476
- trans->cfg = &iwl22000_2ax_cfg_qnj_hr_a0_f0;
3477
- } else {
3478
- /*
3479
- * a step no FPGA
3480
- */
3481
- trans->cfg = &iwl22000_2ac_cfg_hr;
3482
- }
3483
- }
3484
-#endif
3485
-
3486
- iwl_pcie_set_interrupt_capa(pdev, trans);
3616
+ iwl_pcie_set_interrupt_capa(pdev, trans, cfg_trans);
34873617 trans->hw_id = (pdev->device << 16) + pdev->subsystem_device;
34883618 snprintf(trans->hw_id_str, sizeof(trans->hw_id_str),
34893619 "PCI ID: 0x%04X:0x%04X", pdev->device, pdev->subsystem_device);
....@@ -3491,7 +3621,8 @@
34913621 /* Initialize the wait queue for commands */
34923622 init_waitqueue_head(&trans_pcie->wait_command_queue);
34933623
3494
- init_waitqueue_head(&trans_pcie->d0i3_waitq);
3624
+ init_waitqueue_head(&trans_pcie->sx_waitq);
3625
+
34953626
34963627 if (trans_pcie->msix_enabled) {
34973628 ret = iwl_pcie_init_msix_handler(pdev, trans_pcie);
....@@ -3513,20 +3644,65 @@
35133644 trans_pcie->inta_mask = CSR_INI_SET_MASK;
35143645 }
35153646
3516
-#ifdef CONFIG_IWLWIFI_PCIE_RTPM
3517
- trans->runtime_pm_mode = IWL_PLAT_PM_MODE_D0I3;
3518
-#else
3519
- trans->runtime_pm_mode = IWL_PLAT_PM_MODE_DISABLED;
3520
-#endif /* CONFIG_IWLWIFI_PCIE_RTPM */
3647
+#ifdef CONFIG_IWLWIFI_DEBUGFS
3648
+ trans_pcie->fw_mon_data.state = IWL_FW_MON_DBGFS_STATE_CLOSED;
3649
+ mutex_init(&trans_pcie->fw_mon_data.mutex);
3650
+#endif
3651
+
3652
+ iwl_dbg_tlv_init(trans);
35213653
35223654 return trans;
35233655
35243656 out_free_ict:
35253657 iwl_pcie_free_ict(trans);
35263658 out_no_pci:
3527
- free_percpu(trans_pcie->tso_hdr_page);
35283659 destroy_workqueue(trans_pcie->rba.alloc_wq);
35293660 out_free_trans:
35303661 iwl_trans_free(trans);
35313662 return ERR_PTR(ret);
35323663 }
3664
+
3665
+void iwl_trans_pcie_sync_nmi(struct iwl_trans *trans)
3666
+{
3667
+ struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
3668
+ unsigned long timeout = jiffies + IWL_TRANS_NMI_TIMEOUT;
3669
+ bool interrupts_enabled = test_bit(STATUS_INT_ENABLED, &trans->status);
3670
+ u32 inta_addr, sw_err_bit;
3671
+
3672
+ if (trans_pcie->msix_enabled) {
3673
+ inta_addr = CSR_MSIX_HW_INT_CAUSES_AD;
3674
+ sw_err_bit = MSIX_HW_INT_CAUSES_REG_SW_ERR;
3675
+ } else {
3676
+ inta_addr = CSR_INT;
3677
+ sw_err_bit = CSR_INT_BIT_SW_ERR;
3678
+ }
3679
+
3680
+ /* if the interrupts were already disabled, there is no point in
3681
+ * calling iwl_disable_interrupts
3682
+ */
3683
+ if (interrupts_enabled)
3684
+ iwl_disable_interrupts(trans);
3685
+
3686
+ iwl_force_nmi(trans);
3687
+ while (time_after(timeout, jiffies)) {
3688
+ u32 inta_hw = iwl_read32(trans, inta_addr);
3689
+
3690
+ /* Error detected by uCode */
3691
+ if (inta_hw & sw_err_bit) {
3692
+ /* Clear causes register */
3693
+ iwl_write32(trans, inta_addr, inta_hw & sw_err_bit);
3694
+ break;
3695
+ }
3696
+
3697
+ mdelay(1);
3698
+ }
3699
+
3700
+ /* enable interrupts only if there were already enabled before this
3701
+ * function to avoid a case were the driver enable interrupts before
3702
+ * proper configurations were made
3703
+ */
3704
+ if (interrupts_enabled)
3705
+ iwl_enable_interrupts(trans);
3706
+
3707
+ iwl_trans_fw_error(trans);
3708
+}