Quellcode durchsuchen

iwl: bring up the Intel 8265 firmware and scan on the Yoga

The 8265-36 firmware asserted on its first host command and, once past
that, on the LMAC scan and the connect quota.  Follow Linux iwlmvm for
the 8000 family:

- INIT image: no BT_CONFIG (sent only to families below 8000), no
  L0S-exit-timer chicken bit, and the 8000 NIC config (MAC step, radio
  type/step/dash from the PHY SKU) before the rings.
- Runtime image: firmware paging.  The CSS block and paging image after
  the paging separator go into DRAM blocks announced with
  FW_PAGING_BLOCK_CMD right after ALIVE.
- Command variants picked from the firmware's API/capability flags:
  ADD_STA v10 (station_type), TIME_QUOTA_CMD v2 (low_latency dword) and
  the UMAC scan (SCAN_CFG_CMD + SCAN_REQ_UMAC v7, SCAN_COMPLETE_UMAC).
  The 7265D keeps ADD_STA v7, quota v1 and the LMAC scan.
- Diagnostics: per-stage bring-up state, and a firmware assert during a
  command dumps the LMAC (incl. last host command) and UMAC error tables.

On the Yoga 720 the firmware now boots and scans; connecting is not yet
hardware-validated.
Johannes Zellner vor 4 Stunden
Ursprung
Commit
0705239798
5 geänderte Dateien mit 375 neuen und 118 gelöschten Zeilen
  1. 20 4
      AGENTS.md
  2. 2 2
      docs/drivers.html
  3. 301 111
      kernel/iwl_mvm.c
  4. 48 1
      kernel/iwl_trans.c
  5. 4 0
      kernel/iwl_trans.h

+ 20 - 4
AGENTS.md

@@ -1302,7 +1302,24 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   (`apmg_not_supported`).  Its MAC address comes from the extended-NVM
   `MAC_OVERRIDE` section (11, offset 2), with the WFMP `0xA03080/0xA03084`
   registers as the fallback; the 7000 HW-section 0/word 0x15 path is
-  unchanged.  This backend is not yet hardware-validated.
+  unchanged.  Before the rings the transport writes the 8000 NIC config
+  (`iwl_mvm_nic_config()`: MAC step from `CSR_HW_REV` bits 0-1, radio
+  type/step/dash from the PHY SKU, `RADIO_SI` clear).  The runtime image
+  pages part of the UMAC code from host DRAM: `send_paging()` copies the
+  CSS block and the 39-page paging image that follow the `0xaaaabbbb`
+  separator (`iwl_fw_paging()`) into a page plus 32 KB-aligned blocks and
+  sends `FW_PAGING_BLOCK_CMD` (0x4f) right after the runtime ALIVE (Linux
+  does this only for the regular image).  The firmware's API/capability
+  flags select the 8265 command variants: `ADD_STA` v10 (48 bytes,
+  `station_type`, api 30), `TIME_QUOTA_CMD` v2 (16-byte entries, api 38)
+  and the UMAC scan (capa 2): `SCAN_CFG_CMD` (0x0c, `iwl_scan_config_v1`)
+  once in the runtime bring-up and `SCAN_REQ_UMAC` (0x0d) v7 (adaptive
+  dwell) per scan, completed by `SCAN_COMPLETE_UMAC` (0x0f); the channel
+  configs are sized by `N_SCAN_CHANNELS` (TLV 31: 52 here, 40 on the
+  7265D, which keeps the LMAC scan).  A command that ends in a firmware
+  assert dumps the LMAC (24 dwords, `[23]` = last host command) and UMAC
+  error tables once.  On the Yoga the firmware boots and scans; the
+  connect path is not yet hardware-validated.
   The firmware is loaded on first use (`wifi` or the boot autoconnect
   helper), not during kernel init.
   `netdev_shutdown()` always calls `wifi_shutdown()` before a kexec (the RX
@@ -3872,9 +3889,8 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     chat thread at 32x32.
 
 35. WiFi limits (`iwl_trans.c`, `iwl_mvm.c`, `iwl_dvm.c`, `wifi.c`): Intel
-    7265 rev D/3165 (`iwlwifi-7265D-29`), 8265 (`iwlwifi-8265-36`, whose
-    new 8000 secure-section loader and MAC path are not yet
-    hardware-validated) and 6200/6300 (`iwlwifi-6000-4`)
+    7265 rev D/3165 (`iwlwifi-7265D-29`), 8265 (`iwlwifi-8265-36`: boots and scans
+    on the Yoga, connect not yet hardware-validated) and 6200/6300 (`iwlwifi-6000-4`)
     only; a non-D 7265 is logged and will likely fail, and other 6000-family
     parts (6005/6030/6050/6150, which use different firmware files) are not
     probed.  The 6200/6300 DVM path was written against Linux iwldvm without

+ 2 - 2
docs/drivers.html

@@ -466,7 +466,7 @@
 		<ul>
 			<li><strong>Transport.</strong> <span class="file">iwl_trans.c</span> follows Linux iwlwifi for the 7000 family: APM init, one legacy RX queue of 256 × 4 KB RBDs, gen1 128-byte TFDs, byte-count tables in dwords, and the FH service channel loading firmware sections through a 128 KB bounce buffer. The NIC is kept awake (MAC access request held) and interrupts stay masked; PCI INTx is disabled. Host commands use the wide 8-byte header (legacy commands go out as group 1).</li>
 			<li><strong>Firmware.</strong> <code>iwlwifi-7265D-29.ucode</code> ships in the command pack as <code>firmware/iwlwifi-7265D-29.ucode</code> (1,036,312 bytes). It is a single-CPU image with LMAC scan, DQA queues and the old station API. <span class="file">iwl_mvm.c</span> runs the INIT image (NVM read for the MAC address, calibration, PHY-DB collection), then the runtime image (PHY-DB replay, DQA, aux station, PHY context, CAM power, MCC <code>ZZ</code>, station MAC context).</li>
-			<li><strong>8000 firmware (8265).</strong> <code>iwlwifi-8265-36.ucode</code> (API 36, ~2.4 MB) is the Yoga's image. Its TLV section list is split into CPU1 and CPU2 lists by separator entries; every loaded section is acknowledged in <code>FH_UCODE_LOAD_STATUS</code> and the CPU reset is released through <code>RELEASE_CPU_RESET</code>/<code>WFPM_GP2</code> (<code>load_sections_8000</code> in <span class="file">iwl_trans.c</span>). The APMG clock block is skipped (<code>apmg_not_supported</code>), and the MAC comes from the extended NVM's <code>MAC_OVERRIDE</code> section 11 (word 1), falling back to the WFMP <code>0xA03080</code>/<code>0xA03084</code> registers. This path is not yet hardware-validated.</li>
+			<li><strong>8000 firmware (8265).</strong> <code>iwlwifi-8265-36.ucode</code> (API 36, ~2.4 MB) is the Yoga's image. Its TLV section list is split into CPU1 and CPU2 lists by separator entries; every loaded section is acknowledged in <code>FH_UCODE_LOAD_STATUS</code> and the CPU reset is released through <code>RELEASE_CPU_RESET</code>/<code>WFPM_GP2</code> (<code>load_sections_8000</code> in <span class="file">iwl_trans.c</span>). The APMG clock block is skipped (<code>apmg_not_supported</code>), and the MAC comes from the extended NVM's <code>MAC_OVERRIDE</code> section 11 (word 1), falling back to the WFMP <code>0xA03080</code>/<code>0xA03084</code> registers. The transport writes the 8000 NIC config (MAC step, radio type/step/dash) before the rings. The runtime image pages part of the UMAC code from host DRAM: <code>send_paging()</code> copies the CSS block and paging image that follow the paging separator (<code>iwl_fw_paging()</code>) into 32 KB blocks and sends <code>FW_PAGING_BLOCK_CMD</code> right after ALIVE. The firmware's API/capability flags select <code>ADD_STA</code> v10, <code>TIME_QUOTA_CMD</code> v2 and the UMAC scan (<code>SCAN_CFG_CMD</code> once, <code>SCAN_REQ_UMAC</code> v7 per scan, <code>SCAN_COMPLETE_UMAC</code>); the 7265D keeps the LMAC scan. A firmware assert during a command dumps the LMAC and UMAC error tables. The firmware boots and scans on the Yoga; connecting is not yet hardware-validated.</li>
 			<li><strong>Queues.</strong> Command queue 0 (FIFO 7), aux queue 1 (scan probes), BSS queue 4 for the AP station (management and data, BE FIFO).</li>
 			<li><strong>Station.</strong> <span class="file">wifi.c</span> builds open-system authentication and the association request itself, without WMM or HT IEs, so data frames are plain non-QoS 802.11 + LLC/SNAP. Management frames go at 1 Mb/s CCK (6 Mb/s on 5 GHz), data at a fixed 12 Mb/s OFDM (no rate scaling table yet).</li>
 			<li><strong>Security.</strong> WPA2-PSK with CCMP only. The 4-way and group handshakes run in ring 3 (<span class="file">wpa.c</span>); the kernel queues EAPOL frames and installs the TK/GTK with <code>ADD_STA_KEY</code>. TX uses the firmware's CCMP engine with the key embedded in <code>TX_CMD</code>; the host builds the 8-byte CCMP header and its packet number. On the tested 7265D-29 the firmware does not use the installed keys for RX and reports <code>SEC_ENC_ERR</code>, so RX CCMP is decrypted in software by <span class="file">ccmp.c</span> (AES-CCM, RFC 3610) with the same TK/GTK. There is no software replay window yet.</li>
@@ -788,7 +788,7 @@
 			<li><strong>eMMC.</strong> Polled 1-bit/25 MHz PIO; no DMA, IRQ, CMD6 bus-width/high-speed/DDR switch or hotplug. Only the eMMC function is driven; the SDIO/SD functions and SD card reader are not.</li>
 			<li><strong>Storage serialization.</strong> A FAT/floppy operation sets <code>sys_fs_busy</code> and stalls process switching for its duration; the PIT keeps ticking.</li>
 			<li><strong>EC.</strong> The Chrome EC path uses the ACPI v2 memmap only: no MEC host-command interface, EC SCI events, charger current/voltage, charging limit or EC firmware version. The ThinkPad H8 path is limited to its page-selected battery window and has no SCI handler. The IdeaPad path maps the DSDT's EC memory window, reads <code>BAT1</code>/<code>ACAD</code> and writes only the boot OS handshake (there is no ACPI interpreter, no EC SCI/notify handling, and the model/serial strings are the DSDT defaults). Battery/AC is polled by the WM once a second.</li>
-			<li><strong>WiFi.</strong> Intel 7265 rev D/3165 (7265D firmware), 8265 (8265-36 firmware, the 8000 loader is not yet hardware-validated) and 6200/6300 (6000 firmware, written without hardware in the loop); WPA2-PSK/CCMP and open networks, no WPA3/SAE, 802.1X, TKIP or WEP. No roaming, power save, background scan, HT/VHT, aggregation or rate scaling. Group rekeys need the background <code>wifi __keep</code> helper running. RX CCMP falls back to the byte-oriented software AES-CCM path when the firmware rejects the installed keys, so it has no replay window and is CPU-bound at high RX rates.</li>
+			<li><strong>WiFi.</strong> Intel 7265 rev D/3165 (7265D firmware), 8265 (8265-36 firmware: boots and scans on the Yoga, connect not yet hardware-validated) and 6200/6300 (6000 firmware, written without hardware in the loop); WPA2-PSK/CCMP and open networks, no WPA3/SAE, 802.1X, TKIP or WEP. No roaming, power save, background scan, HT/VHT, aggregation or rate scaling. Group rekeys need the background <code>wifi __keep</code> helper running. RX CCMP falls back to the byte-oriented software AES-CCM path when the firmware rejects the installed keys, so it has no replay window and is CPU-bound at high RX rates.</li>
 			<li><strong>RTL8821AU.</strong> High-speed EHCI/xHCI only (no UHCI/OHCI bulk). No IQ calibration, thermal power tracking, DIG, BT coexistence or by-rate/regulatory TX power tables (the eFuse base index is used for every rate); 20 MHz legacy rates only. Only one bulk device can stream on xHCI at a time (single bulk ring), so it does not mix with an ASIX dongle or a USB stick transfer.</li>
 			<li><strong>Suspend.</strong> There is no S0ix/suspend path; package C-states and the EC sleep handshake remain firmware-managed.</li>
 		</ul>

+ 301 - 111
kernel/iwl_mvm.c

@@ -1,8 +1,8 @@
 /* Intel 7265D/3165/8265 firmware command layer: see iwl_mvm.h.
  *
  * Follows Linux iwlmvm for the 7265D-29 API (no unified image, LMAC scan,
- * DQA queues, old station API, ADD_STA v7, ADD_STA_KEY v1, PHY context v1,
- * MAC context v1, TX_CMD v6, legacy RX_PHY + RX_MPDU).  The 8265 uses the
+ * DQA queues, old station API, ADD_STA v7 (v10 on the 8265), ADD_STA_KEY
+ * v1, PHY context v1, MAC context v1, TX_CMD v6, legacy RX_PHY + RX_MPDU).  The 8265 uses the
  * same command layer with its 8000-family firmware; the transport handles
  * the secure section loader and the MAC comes from the extended NVM.
  *
@@ -42,12 +42,17 @@
 #define PHY_DB_CMD               0x6c
 #define SCAN_OFFLOAD_COMPLETE    0x6d
 #define POWER_TABLE_CMD          0x77
+#define FW_PAGING_BLOCK_CMD      0x4f
 #define NVM_ACCESS_CMD           0x88
 #define TX_ANT_CONFIGURATION_CMD 0x98
 #define BT_CONFIG                0x9b
 #define REPLY_RX_PHY_CMD         0xc0
 #define REPLY_RX_MPDU_CMD        0xc1
 #define MCC_UPDATE_CMD           0xc8
+/* UMAC scan (IWL_ALWAYS_LONG_GROUP, sent with the wide header as group 1) */
+#define SCAN_CFG_CMD             0x0c
+#define SCAN_REQ_UMAC            0x0d
+#define SCAN_COMPLETE_UMAC       0x0f
 #define DQA_ENABLE_CMD           ((5u << 8) | 0x00)   /* DATA_PATH_GROUP */
 
 #define ACTION_ADD     1
@@ -102,11 +107,7 @@ struct binding_cmd {                 /* BINDING_CMD_API_S_VER_1 */
 	unsigned int id_and_color, action, macs[3], phy;
 } PACKED;
 
-struct quota_cmd {                   /* TIME_QUOTA_ALLOCATION_CMD v1 */
-	struct { unsigned int id_and_color, quota, max_duration; } q[4];
-} PACKED;
-
-struct add_sta_cmd {                 /* ADD_STA_CMD_API_S_VER_7 */
+struct add_sta_cmd {                 /* ADD_STA_CMD_API_S_VER_10 */
 	unsigned char add_modify, awake_acs;
 	unsigned short tid_disable_tx;
 	unsigned int mac_id_n_color;
@@ -116,9 +117,12 @@ struct add_sta_cmd {                 /* ADD_STA_CMD_API_S_VER_7 */
 	unsigned short res3;
 	unsigned int station_flags, station_flags_msk;
 	unsigned char add_ba_tid, remove_ba_tid;
-	unsigned short add_ba_ssn, sleep_tx_count, sleep_state_flags;
+	unsigned short add_ba_ssn, sleep_tx_count;
+	unsigned char sleep_state_flags, station_type;  /* v7: u16 flags */
 	unsigned short assoc_id, beamform_flags;
 	unsigned int tfd_queue_msk;
+	unsigned short rx_ba_window;     /* v10 only: v7 ends here (44) */
+	unsigned char sp_length, uapsd_acs;
 } PACKED;
 
 struct sta_key_cmd {                 /* ADD_MODIFY_STA_KEY_API_S_VER_1 */
@@ -183,7 +187,7 @@ typedef char chk1a[__builtin_offsetof(struct mac_ctx_cmd, filter_flags) == 52
 		   ? 1 : -1];
 typedef char chk1b[__builtin_offsetof(struct mac_ctx_cmd, is_assoc) == 100
 		   ? 1 : -1];
-typedef char chk2[sizeof(struct add_sta_cmd) == 44 ? 1 : -1];
+typedef char chk2[sizeof(struct add_sta_cmd) == 48 ? 1 : -1];
 typedef char chk2a[__builtin_offsetof(struct add_sta_cmd, addr) == 8 ? 1 : -1];
 typedef char chk2b[__builtin_offsetof(struct add_sta_cmd, tfd_queue_msk) == 40
 		   ? 1 : -1];
@@ -207,7 +211,9 @@ static struct {
 	unsigned int chan;           /* current PHY context channel */
 	int bound;                   /* binding + quota active */
 	int ap_sta;                  /* AP station added */
-	unsigned int alive_status, scd_base, err_table;
+	unsigned int alive_status, scd_base, err_table, umac_err;
+	unsigned int pg_css, pg_base;
+	int err_dumped;              /* error tables printed for this load */  /* 8265 paging DRAM (CSS, 32 KB blocks) */
 	int alive;
 	int init_complete;
 	unsigned char *phydb;        /* [type u16][chg u16][len u16][pad][data] */
@@ -249,6 +255,11 @@ static void put16(unsigned char *p, unsigned int v)
 	p[0] = v; p[1] = v >> 8;
 }
 
+static void put32(unsigned char *p, unsigned int v)
+{
+	put16(p, v); put16(p + 2, v >> 16);
+}
+
 static unsigned int get16(const unsigned char *p)
 {
 	return p[0] | (p[1] << 8);
@@ -259,9 +270,15 @@ static unsigned int get32(const unsigned char *p)
 	return p[0] | (p[1] << 8) | (p[2] << 16) | ((unsigned int)p[3] << 24);
 }
 
+static void dump_error_log(void);
+
 static int cmd(unsigned int id, const void *data, unsigned int len)
 {
-	return iwl_send_cmd(id, data, len, 0, 0) < 0 ? -1 : 0;
+	if (iwl_send_cmd(id, data, len, 0, 0) >= 0)
+		return 0;
+	if (iwl_fatal())           /* firmware assert: print why, once */
+		dump_error_log();
+	return -1;
 }
 
 /* Command with a 32-bit status response (iwl_mvm_send_cmd_pdu_status). */
@@ -389,6 +406,10 @@ static void rx_handler(const struct iwl_pkt *pkt)
 			M.alive_status = get16(d);
 			M.err_table = get32(d + 20);
 			M.scd_base = get32(d + 40);
+			/* alive v3: umac error_info_addr at 60 (68 bytes);
+			 * v4 has two LMACs and puts it at 108 (116). */
+			M.umac_err = n >= 68 ? get32(d + (n >= 116 ? 108 : 60))
+					     : 0;
 			M.alive = 1;
 		}
 		break;
@@ -429,8 +450,12 @@ static void rx_handler(const struct iwl_pkt *pkt)
 		}
 		break;
 	case SCAN_OFFLOAD_COMPLETE:
+	case SCAN_COMPLETE_UMAC:
+		/* lmac: status at 2; iwl_umac_scan_complete: status at 6.
+		 * IWL_SCAN_OFFLOAD_COMPLETED = 1 in both. */
 		M.scanning = 0;
-		M.scan_ok = n >= 3 && d[2] == 1;
+		M.scan_ok = pkt->cmd == SCAN_COMPLETE_UMAC ? n >= 7 && d[6] == 1
+							   : n >= 3 && d[2] == 1;
 		wifi_scan_done(M.scan_ok);
 		break;
 	case TIME_EVENT_NOTIFICATION:
@@ -458,25 +483,77 @@ int iwl_mvm_poll(void)
 }
 
 /* ---- bring-up ---------------------------------------------------------- */
-static void dump_error_log(void)
+/* LMAC table (struct iwl_error_event_table): [1] error_id, [20] log_pc,
+ * [23] hcmd (last host command).  UMAC table (iwl_umac_error_event_table):
+ * [1] error_id, [2..5] blink/ilink, [6..8] data, [13] cmd_header. */
+static void dump_table(const char *tag, unsigned int a, unsigned int n)
 {
 	unsigned int i;
 
-	if (!M.err_table || M.err_table >= 0x01000000u)
+	if (!a)
 		return;
-	serial_puts(SERIAL_COM1, "iwl: error log:");
-	for (i = 0; i < 16; i++) {
+	serial_puts(SERIAL_COM1, tag);
+	for (i = 0; i < n; i++) {
 		serial_puts(SERIAL_COM1, " ");
-		serial_puthex(SERIAL_COM1, iwl_mem_rd32(M.err_table + i * 4));
+		serial_puthex(SERIAL_COM1, iwl_mem_rd32(a + i * 4));
 	}
 	serial_puts(SERIAL_COM1, "\n");
 }
 
+static void dump_error_log(void)
+{
+	if (M.err_dumped)
+		return;
+	M.err_dumped = 1;
+	if (M.err_table < 0x01000000u)
+		dump_table("iwl: error log:", M.err_table, 24);
+	if (M.umac_err >= 0x00800000u)
+		dump_table("iwl: umac log:", M.umac_err, 16);
+}
+
+/* 8265 runtime image: the UMAC pages part of its code from host DRAM
+ * (Linux iwl_init_paging(): only IWL_UCODE_REGULAR has paging_mem_size).
+ * Block 0 is the 4 KB CSS, blocks 1..n are 32 KB (8 pages); the last one
+ * may be short.  FW_PAGING_BLOCK_CMD v1 takes 4 KB page numbers. */
+static int send_paging(void)
+{
+	const unsigned char *css, *pg;
+	unsigned int css_len, pg_len, pages, nblk, i, c[3 + 33];
+
+	if (iwl_fw_paging(IWL_IMG_RT, &css, &css_len, &pg, &pg_len) < 0)
+		return 0;
+	pages = pg_len >> 12;
+	nblk = (pages + 7) >> 3;
+	if ((pg_len & 0xfff) || !nblk || nblk > 32 || css_len > 4096)
+		return -1;
+	if (!M.pg_css) {
+		M.pg_css = mm_alloc_page();
+		M.pg_base = mm_alloc_pages(nblk * 8 + 7);
+		if (!M.pg_css || !M.pg_base)
+			return -1;
+		M.pg_base = (M.pg_base + 0x7fffu) & ~0x7fffu;  /* order-3 */
+	}
+	/* Fresh copy on every load: the firmware writes dirty pages back. */
+	iwl_memzero((void *)M.pg_css, 4096);
+	iwl_memcpy((void *)M.pg_css, css, css_len);
+	iwl_memcpy((void *)M.pg_base, pg, pg_len);
+	iwl_memzero(c, sizeof(c));
+	/* IS_SECURED | IS_ENABLED | pages in the last block; 2^15 blocks */
+	c[0] = (1u << 9) | (1u << 8) | (pages - (nblk - 1) * 8);
+	c[1] = 15;
+	c[2] = nblk;
+	c[3] = M.pg_css >> 12;
+	for (i = 0; i < nblk; i++)
+		c[4 + i] = (M.pg_base + i * 0x8000u) >> 12;
+	return cmd(FW_PAGING_BLOCK_CMD, c, sizeof(c));
+}
+
 static int load_and_wait_alive(int img)
 {
 	unsigned int t;
 
 	M.alive = 0;
+	M.err_dumped = 0;
 	if (iwl_load_fw(img) < 0)
 		return -1;
 	for (t = 0; t < 2000 && !M.alive; t++) {
@@ -494,6 +571,10 @@ static int load_and_wait_alive(int img)
 		return -1;
 	}
 	iwl_fw_alive(M.scd_base);
+	if (img == IWL_IMG_RT && send_paging() < 0) {
+		M.state = "rt: paging";
+		return -1;
+	}
 	return 0;
 }
 
@@ -622,16 +703,32 @@ static int run_init_image(void)
 		return -1;
 	M.phydb_len = 0;
 	M.init_complete = 0;
+	M.state = "init: ALIVE";
 	if (load_and_wait_alive(IWL_IMG_INIT) < 0)
 		return -1;
-	if (send_bt_config() < 0 || read_nvm() < 0)
+	/* Linux's iwl_run_init_mvm_ucode() sends BT_CONFIG only for device
+	 * families below 8000.  The 8265's INIT image asserts on it (the
+	 * runtime image sends it later, iwl_mvm_up()), so skip it here. */
+	if (iwl_subfamily() != IWL_SUB_8265) {
+		M.state = "init: BT config";
+		if (send_bt_config() < 0)
+			return -1;
+	}
+	M.state = "init: NVM";
+	if (read_nvm() < 0)
 		return -1;
 	if (iwl_rfkill()) {
+		M.state = "init: RF-kill";
 		logs("radio is off (hardware RF-kill)");
 		return -1;
 	}
-	if (send_tx_ant() < 0 || send_phy_cfg(IWL_IMG_INIT) < 0)
+	M.state = "init: TX antennas";
+	if (send_tx_ant() < 0)
+		return -1;
+	M.state = "init: PHY config";
+	if (send_phy_cfg(IWL_IMG_INIT) < 0)
 		return -1;
+	M.state = "init: calibration";
 	for (t = 0; t < 2000 && !M.init_complete; t++) {
 		if (iwl_rx_poll() < 0)
 			break;
@@ -666,8 +763,12 @@ static int enable_queue(int q, unsigned int sta, unsigned int tid,
 static int add_sta(struct add_sta_cmd *c)
 {
 	unsigned int status = 0;
+	/* IWL_UCODE_TLV_API_STA_TYPE (api[0] bit 30, the 8265): v10. */
+	int v10 = (iwl_fw()->api[0] >> 30) & 1;
 
-	if (cmd_status(ADD_STA, c, sizeof(*c), &status) < 0)
+	if (!v10)
+		c->station_type = 0;
+	if (cmd_status(ADD_STA, c, v10 ? sizeof(*c) : 44, &status) < 0)
 		return -1;
 	if ((status & 0xff) != 1) {
 		iwl_loghex("ADD_STA failed, status", status);
@@ -687,6 +788,7 @@ static int add_aux_sta(void)
 	c.mac_id_n_color = MAC_INDEX_AUX;
 	c.tfd_queue_msk = 1u << IWL_Q_AUX;
 	c.tid_disable_tx = 0xffff;
+	c.station_type = 4;                  /* IWL_STA_AUX_ACTIVITY */
 	return add_sta(&c);
 }
 
@@ -774,6 +876,52 @@ static int mac_ctx(unsigned int action, int assoc, unsigned short aid,
 	return 0;
 }
 
+static const unsigned char scan_channels[] = {
+	1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
+	36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120,
+	124, 128, 132, 136, 140, 149, 153, 157, 161, 165,
+};
+
+/* Firmware with IWL_UCODE_TLV_CAPA_UMAC_SCAN (capa[0] bit 2: the 8265)
+ * asserts on the LMAC SCAN_OFFLOAD_REQUEST; Linux uses the UMAC scan. */
+static int umac_scan(void)
+{
+	return (iwl_fw()->capa[0] >> 2) & 1;
+}
+
+static unsigned int n_scan_ch(void)
+{
+	unsigned int n = iwl_fw()->n_scan_ch;
+
+	return n >= sizeof(scan_channels) && n <= 64 ? n : 40;
+}
+
+/* SCAN_CFG_CMD, struct iwl_scan_config_v1 (Linux iwl_mvm_config_scan()
+ * for a non-CDB device), once after the runtime image is up. */
+static int scan_config(void)
+{
+	unsigned char *c = M.scratch;
+	unsigned int n = sizeof(scan_channels), nsc = n_scan_ch();
+
+	if (!umac_scan())
+		return 0;
+	iwl_memzero(c, 36 + nsc);
+	/* ACTIVATE | ALLOW_CHUB_REQS | SET_TX/RX_CHAINS | SET_AUX_STA_ID |
+	 * SET_ALL_TIMES | SET_CHANNEL_FLAGS | SET_LEGACY_RATES |
+	 * SET_MAC_ADDR | CLEAR_FRAGMENTED | N_CHANNELS(n) */
+	put32(c, 0x0002ef09u | (n << 26));
+	put32(c + 4, M.valid_tx_ant);
+	put32(c + 8, M.valid_rx_ant);
+	put32(c + 12, 0x0fff0fffu);          /* all CCK+OFDM, basic+supported */
+	/* out_of_channel_time / suspend_time: 0 (IWL_SCAN_TYPE_UNASSOC) */
+	c[24] = 10; c[25] = 110; c[26] = 44; c[27] = 90;   /* dwells */
+	iwl_memcpy(c + 28, M.mac, 6);
+	c[34] = IWL_STA_AUX;                 /* bcast_sta_id */
+	c[35] = 0x0f;                        /* EBS | ACCURATE | ADD | P2A */
+	iwl_memcpy(c + 36, scan_channels, n);
+	return cmd(SCAN_CFG_CMD, c, 36 + nsc);
+}
+
 static int run_rt_image(void)
 {
 	unsigned int one = 0;
@@ -783,30 +931,46 @@ static int run_rt_image(void)
 	iwl_stop_device();
 	if (iwl_start_hw() < 0)
 		return -1;
+	M.state = "rt: ALIVE";
 	if (load_and_wait_alive(IWL_IMG_RT) < 0)
 		return -1;
+	M.state = "rt: TX antennas";
 	if (send_tx_ant() < 0)
 		return -1;
+	M.state = "rt: PHY DB";
 	if (phydb_send_type(1) < 0 || phydb_send_type(2) < 0 ||
 	    phydb_send_type(4) < 0 || phydb_send_type(5) < 0)
 		return -1;
-	if (send_phy_cfg(IWL_IMG_RT) < 0 || send_bt_config() < 0)
+	M.state = "rt: PHY config";
+	if (send_phy_cfg(IWL_IMG_RT) < 0)
+		return -1;
+	M.state = "rt: BT config";
+	if (send_bt_config() < 0)
 		return -1;
+	M.state = "rt: DQA";
 	if (cmd(DQA_ENABLE_CMD, &one, 4) < 0)     /* cmd_queue = 0 */
 		return -1;
+	M.state = "rt: aux station";
 	if (add_aux_sta() < 0)
 		return -1;
+	M.state = "rt: PHY context";
 	if (phy_ctx(ACTION_ADD, 1) < 0)
 		return -1;
 	one = 0;                                   /* device power: CAM */
+	M.state = "rt: power table";
 	if (cmd(POWER_TABLE_CMD, &one, 4) < 0)
 		return -1;
 	/* LAR: ask for the current (NVM default) regulatory domain. */
 	iwl_memzero(mcc, sizeof(mcc));
 	mcc[0] = 'Z'; mcc[1] = 'Z';                /* le16: 'Z' << 8 | 'Z' */
 	mcc[2] = 0x10;                             /* MCC_SOURCE_GET_CURRENT */
+	M.state = "rt: MCC";
 	if (iwl_send_cmd(MCC_UPDATE_CMD, mcc, sizeof(mcc), 0, 0) < 0)
 		logs("MCC update failed (continuing)");
+	M.state = "rt: scan config";
+	if (scan_config() < 0)
+		return -1;
+	M.state = "rt: MAC context";
 	if (mac_ctx(ACTION_ADD, 0, 0, 100, 1) < 0)
 		return -1;
 	return 0;
@@ -845,11 +1009,9 @@ int iwl_mvm_up(unsigned char mac[6])
 		M.valid_rx_ant = 1;
 	iwl_set_rx_handler(rx_handler);
 	if (run_init_image() < 0 || run_rt_image() < 0) {
+		logs(M.state ? M.state : "bring-up failed");
 		dump_error_log();
 		iwl_stop_device();
-		if (M.state && M.state[0] != 'r' && M.state[0] != 'i')
-			return -1;
-		M.state = "firmware start failed";
 		return -1;
 	}
 	M.up = 1;
@@ -882,95 +1044,120 @@ void iwl_mvm_down(void)
 }
 
 /* ---- scan -------------------------------------------------------------- */
-static const unsigned char scan_channels[] = {
-	1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
-	36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120,
-	124, 128, 132, 136, 140, 149, 153, 157, 161, 165,
-};
 
 int iwl_mvm_scan_running(void)
 {
 	return M.scanning;
 }
 
-int iwl_mvm_scan_start(void)
+/* struct iwl_scan_probe_req_v1: mac_header, band_data[2] and
+ * common_data segments, then the 512-byte template. */
+static void build_preq(unsigned char *preq)
 {
-	struct scan_req_lmac *c;
-	struct scan_chan_lmac *ch;
-	unsigned char *preq, *buf;
-	unsigned int i, n = sizeof(scan_channels), total, rx = M.valid_rx_ant;
 	static const unsigned char rates24[] = { 1, 8, 0x82, 0x84, 0x8b, 0x96,
 						 0x0c, 0x12, 0x18, 0x24,
 						 50, 4, 0x30, 0x48, 0x60, 0x6c };
 	static const unsigned char rates5[] = { 1, 8, 0x8c, 0x12, 0x98, 0x24,
 						0xb0, 0x48, 0x60, 0x6c };
+	unsigned char *f = preq + 16;
+	unsigned int i, o;
+
+	f[0] = 0x40;                      /* probe request */
+	for (i = 0; i < 6; i++) {
+		f[4 + i] = 0xff;
+		f[10 + i] = M.mac[i];
+		f[16 + i] = 0xff;
+	}
+	/* f[24..25]: empty SSID IE, filled by the firmware */
+	put16(preq + 0, 0);               /* mac_header offset */
+	put16(preq + 2, 26);              /* + empty SSID */
+	o = 26;
+	iwl_memcpy(f + o, rates24, sizeof(rates24));
+	put16(preq + 4, o);
+	put16(preq + 6, sizeof(rates24));
+	o += sizeof(rates24);
+	iwl_memcpy(f + o, rates5, sizeof(rates5));
+	put16(preq + 8, o);
+	put16(preq + 10, sizeof(rates5));
+	o += sizeof(rates5);
+	put16(preq + 12, o);              /* common data: none */
+	put16(preq + 14, 0);
+}
+
+int iwl_mvm_scan_start(void)
+{
+	struct scan_req_lmac *c;
+	struct scan_chan_lmac *ch;
+	unsigned char *buf, *p;
+	unsigned int i, n = sizeof(scan_channels), total, rx = M.valid_rx_ant;
+	unsigned int nsc = n_scan_ch(), id;
 
 	if (!M.up || M.scanning)
 		return -1;
-	if (n > 40)
-		n = 40;                          /* n_scan_channels TLV */
 	buf = M.scratch;
 	iwl_memzero(buf, 4096);
-	c = (struct scan_req_lmac *)buf;
-	c->n_channels = n;
-	c->active_dwell = 10;
-	c->passive_dwell = 110;
-	c->fragmented_dwell = 44;
-	c->extended_dwell = 90;
-	c->rx_chain_select = (rx << 1) | (rx << 7) | (rx << 4) | 1;
-	/* PASS_ALL | EXTENDED_DWELL */
-	c->scan_flags = (1u << 0) | (1u << 7);
-	c->flags = 1;                            /* first channel: 2.4 GHz */
-	c->filter_flags = (1u << 2) | (1u << 6); /* ACCEPT_GRP | IN_BEACON */
-	c->tx_cmd[0].tx_flags = TX_FLG_SEQ_CTL | TX_FLG_BT_DIS;
-	c->tx_cmd[0].rate_n_flags = PLCP_1M | RATE_CCK | RATE_ANT_A;
-	c->tx_cmd[0].sta_id = IWL_STA_AUX;
-	c->tx_cmd[1].tx_flags = TX_FLG_SEQ_CTL | TX_FLG_BT_DIS;
-	c->tx_cmd[1].rate_n_flags = PLCP_6M | RATE_ANT_A;
-	c->tx_cmd[1].sta_id = IWL_STA_AUX;
-	c->scan_prio = 6;                        /* IWL_SCAN_PRIORITY_EXT_6 */
-	c->iter_num = 1;
-	c->schedule[0].iterations = 1;
-	c->schedule[0].full_scan_mul = 1;
-	ch = (struct scan_chan_lmac *)(buf + sizeof(*c));
-	for (i = 0; i < n; i++) {
-		ch[i].channel_num = scan_channels[i];
-		ch[i].iter_count = 1;
-		ch[i].flags = 1u << 28;          /* UNIFIED_SCAN_CHANNEL_PARTIAL */
-	}
-	/* struct iwl_scan_probe_req_v1 after n_scan_channels (40) entries:
-	 * mac_header, band_data[2], common_data segments, then 512 bytes. */
-	preq = buf + sizeof(*c) + 40 * sizeof(struct scan_chan_lmac);
-	{
-		unsigned char *f = preq + 16;
-		unsigned int o = 0;
-
-		f[0] = 0x40;                      /* probe request */
-		for (i = 0; i < 6; i++) {
-			f[4 + i] = 0xff;
-			f[10 + i] = M.mac[i];
-			f[16 + i] = 0xff;
+	if (umac_scan()) {
+		/* SCAN_REQ_UMAC v7 (IWL_UCODE_TLV_API_ADAPTIVE_DWELL, which
+		 * the 8265-36 has): 48-byte header, n_scan_ch channel
+		 * configs, tail v1 (schedule, delay, probe request, 20
+		 * direct-scan SSIDs; slot 0 all zero = the wildcard). */
+		put32(buf + 8, 6);                /* ooc_priority EXT_6 */
+		put16(buf + 12, (1u << 2) | (1u << 13)); /* PASS_ALL|ADWELL */
+		buf[16] = 10;                     /* active dwell */
+		buf[17] = 110;                    /* passive dwell */
+		buf[18] = 44;                     /* fragmented dwell */
+		buf[19] = 2;                      /* adwell_default_n_aps */
+		buf[20] = 10;                     /* ... _social */
+		put16(buf + 22, 300);             /* adwell max budget (full) */
+		put32(buf + 40, 6);               /* scan_priority EXT_6 */
+		buf[45] = n;                      /* channel param count */
+		for (i = 0; i < n; i++) {
+			p = buf + 48 + i * 8;
+			p[0] = 1;                 /* probe direct_scan[0] */
+			p[4] = scan_channels[i];
+			p[5] = 1;                 /* iter_count */
 		}
-		f[24] = 0;                        /* SSID IE, filled by fw */
-		f[25] = 0;
-		put16(preq + 0, 0);               /* mac_header offset */
-		put16(preq + 2, 26);              /* + empty SSID */
-		o = 26;
-		iwl_memcpy(f + o, rates24, sizeof(rates24));
-		put16(preq + 4, o);
-		put16(preq + 6, sizeof(rates24));
-		o += sizeof(rates24);
-		iwl_memcpy(f + o, rates5, sizeof(rates5));
-		put16(preq + 8, o);
-		put16(preq + 10, sizeof(rates5));
-		o += sizeof(rates5);
-		put16(preq + 12, o);              /* common data: none */
-		put16(preq + 14, 0);
+		p = buf + 48 + nsc * 8;
+		p[2] = 1;                         /* schedule[0].iter_count */
+		build_preq(p + 12);
+		total = 48 + nsc * 8 + 12 + 16 + 512 + 20 * 34;
+		id = SCAN_REQ_UMAC;
+	} else {
+		c = (struct scan_req_lmac *)buf;
+		c->n_channels = n;
+		c->active_dwell = 10;
+		c->passive_dwell = 110;
+		c->fragmented_dwell = 44;
+		c->extended_dwell = 90;
+		c->rx_chain_select = (rx << 1) | (rx << 7) | (rx << 4) | 1;
+		/* PASS_ALL | EXTENDED_DWELL */
+		c->scan_flags = (1u << 0) | (1u << 7);
+		c->flags = 1;                     /* first channel: 2.4 GHz */
+		c->filter_flags = (1u << 2) | (1u << 6); /* GRP | IN_BEACON */
+		c->tx_cmd[0].tx_flags = TX_FLG_SEQ_CTL | TX_FLG_BT_DIS;
+		c->tx_cmd[0].rate_n_flags = PLCP_1M | RATE_CCK | RATE_ANT_A;
+		c->tx_cmd[0].sta_id = IWL_STA_AUX;
+		c->tx_cmd[1].tx_flags = TX_FLG_SEQ_CTL | TX_FLG_BT_DIS;
+		c->tx_cmd[1].rate_n_flags = PLCP_6M | RATE_ANT_A;
+		c->tx_cmd[1].sta_id = IWL_STA_AUX;
+		c->scan_prio = 6;                 /* IWL_SCAN_PRIORITY_EXT_6 */
+		c->iter_num = 1;
+		c->schedule[0].iterations = 1;
+		c->schedule[0].full_scan_mul = 1;
+		ch = (struct scan_chan_lmac *)(buf + sizeof(*c));
+		for (i = 0; i < n; i++) {
+			ch[i].channel_num = scan_channels[i];
+			ch[i].iter_count = 1;
+			ch[i].flags = 1u << 28;   /* UNIFIED_SCAN_CHANNEL_PARTIAL */
+		}
+		/* the probe request follows n_scan_ch channel entries */
+		build_preq(buf + sizeof(*c) + nsc * sizeof(*ch));
+		total = sizeof(*c) + nsc * sizeof(*ch) + 16 + 512;
+		id = SCAN_OFFLOAD_REQUEST_CMD;
 	}
-	total = sizeof(*c) + 40 * sizeof(struct scan_chan_lmac) + 16 + 512;
 	M.scanning = 1;
 	M.scan_ok = 0;
-	if (cmd(SCAN_OFFLOAD_REQUEST_CMD, buf, total) < 0) {
+	if (cmd(id, buf, total) < 0) {
 		M.scanning = 0;
 		return -1;
 	}
@@ -978,23 +1165,33 @@ int iwl_mvm_scan_start(void)
 }
 
 /* ---- connection --------------------------------------------------------- */
+/* TIME_QUOTA_CMD for the four bindings: v1 entries are id_and_color,
+ * quota, max_duration; v2 (IWL_UCODE_TLV_API_QUOTA_LOW_LATENCY, api 38 =
+ * api[1] bit 6: the 8265) adds a low_latency dword.  `on` gives binding 0
+ * the whole IWL_MVM_MAX_QUOTA (128); the other entries are invalid. */
+static int send_quota(int on)
+{
+	unsigned int q[16], i, st = (iwl_fw()->api[1] >> 6) & 1 ? 4 : 3;
+
+	iwl_memzero(q, sizeof(q));
+	for (i = 0; i < 4; i++)
+		q[i * st] = CTXT_INVALID;
+	if (on) {
+		q[0] = 0;
+		q[1] = 128;
+	}
+	return cmd(TIME_QUOTA_CMD, q, 16 * st);
+}
+
 static int bind_and_quota(unsigned int action)
 {
 	struct binding_cmd b;
-	struct quota_cmd q;
-	unsigned int status = 0, i;
+	unsigned int status = 0;
 
 	/* Removal: drop the quota first, then the binding (Linux order in
 	 * iwl_mvm_unassign_vif_chanctx()). */
-	if (action == ACTION_REMOVE) {
-		for (i = 0; i < 4; i++) {
-			q.q[i].id_and_color = CTXT_INVALID;
-			q.q[i].quota = 0;
-			q.q[i].max_duration = 0;
-		}
-		if (cmd(TIME_QUOTA_CMD, &q, sizeof(q)) < 0)
-			return -1;
-	}
+	if (action == ACTION_REMOVE && send_quota(0) < 0)
+		return -1;
 	b.id_and_color = 0;               /* binding id = PHY context 0 */
 	b.action = action;
 	b.macs[0] = action == ACTION_REMOVE ? CTXT_INVALID : 0;
@@ -1006,14 +1203,7 @@ static int bind_and_quota(unsigned int action)
 	}
 	if (action == ACTION_REMOVE)
 		return 0;
-	for (i = 0; i < 4; i++) {
-		q.q[i].id_and_color = CTXT_INVALID;
-		q.q[i].quota = 0;
-		q.q[i].max_duration = 0;
-	}
-	q.q[0].id_and_color = 0;
-	q.q[0].quota = 128;
-	return cmd(TIME_QUOTA_CMD, &q, sizeof(q));
+	return send_quota(1);
 }
 
 static int add_ap_sta(int modify, unsigned short aid)

+ 48 - 1
kernel/iwl_trans.c

@@ -670,6 +670,8 @@ int iwl_fw_parse(void)
 			S->fw.capa[le32(p)] = le32(p + 4);
 		else if (t == TLV_PHY_SKU && l >= 4)
 			S->fw.phy_sku = le32(p);
+		else if (t == 31 && l >= 4)        /* N_SCAN_CHANNELS */
+			S->fw.n_scan_ch = le32(p);
 		else if (t == TLV_DEF_CALIB && l >= 12) {
 			unsigned int type = le32(p);
 			/* enum iwl_ucode_type: 0 REGULAR, 1 INIT */
@@ -685,6 +687,37 @@ int iwl_fw_parse(void)
 	return 0;
 }
 
+/* 8000 paging (Linux iwl_fill_paging_mem()): in the image's section list
+ * the PAGING separator is followed by the CPU2 paging CSS block and then
+ * the paging image.  Returns 0 and both sections when the image has them. */
+int iwl_fw_paging(int img, const unsigned char **css, unsigned int *css_len,
+		  const unsigned char **pg, unsigned int *pg_len)
+{
+	unsigned int want = img == IWL_IMG_INIT ? TLV_SEC_INIT : TLV_SEC_RT;
+	const unsigned char *d = S->fw_data;
+	unsigned int off = 88, seen = 0;
+
+	while (S->fam->secure8000 && off + 8 <= S->fw_size) {
+		unsigned int t = le32(d + off), l = le32(d + off + 4);
+		const unsigned char *p = d + off + 8;
+
+		if (t == want && l > 4) {
+			if (seen == 1) {
+				*css = p + 4;
+				*css_len = l - 4;
+			} else if (seen == 2) {
+				*pg = p + 4;
+				*pg_len = l - 4;
+				return 0;
+			}
+			if (seen || le32(p) == SEC_PAGING)
+				seen++;
+		}
+		off += 8 + ((l + 3) & ~3u);
+	}
+	return -1;
+}
+
 /* ---- hardware bring-up ------------------------------------------------- */
 int iwl_rfkill(void)
 {
@@ -723,7 +756,10 @@ static int prepare_card(void)
 
 static int apm_init(void)
 {
-	iwl_set(CSR_GIO_CHICKEN_BITS, GIO_CHICKEN_DIS_L0S_TIMER);
+	/* Linux sets the L0S-exit-timer workaround only for families below
+	 * 8000; the 8265's CSR does not use it. */
+	if (!S->fam->secure8000)
+		iwl_set(CSR_GIO_CHICKEN_BITS, GIO_CHICKEN_DIS_L0S_TIMER);
 	iwl_set(CSR_GIO_CHICKEN_BITS, GIO_CHICKEN_L1A_NO_L0S_RX);
 	iwl_set(CSR_DBG_HPET_MEM_REG, 0xffff0000u);
 	iwl_set(CSR_HW_IF_CONFIG_REG, HW_IF_HAP_WAKE_L1A);
@@ -1094,6 +1130,17 @@ int iwl_load_fw(int img)
 	/* iwl_op_mode_nic_config(): radio SKU bits (DVM) before the rings. */
 	if (S->nic_config)
 		S->nic_config();
+	if (S->fam->secure8000) {
+		/* iwl_mvm_nic_config(): MAC step (the 8000 CSR_HW_REV keeps the
+		 * step in bits 0-1, no dash) and the radio type/step/dash from
+		 * the PHY SKU; RADIO_SI/MAC_SI stay clear on 8000. */
+		unsigned int k = S->fw.phy_sku;
+
+		iwl_wr(CSR_HW_IF_CONFIG_REG,
+		       (iwl_rd(CSR_HW_IF_CONFIG_REG) & ~0xff2fu) |
+		       (S->hw_rev & 3) << 2 | (k & 3) << 10 |
+		       ((k >> 2) & 3) << 14 | ((k >> 4) & 3) << 12);
+	}
 	rx_init();
 	tx_init();
 	if (S->fam->shadow_reg)

+ 4 - 0
kernel/iwl_trans.h

@@ -55,6 +55,7 @@ typedef void (*iwl_rx_handler)(const struct iwl_pkt *pkt);
 struct iwl_fw_info {
 	unsigned int api[4], capa[4];
 	unsigned int phy_sku;
+	unsigned int n_scan_ch;      /* IWL_UCODE_TLV_N_SCAN_CHANNELS */
 	unsigned int flow_trigger[2], event_trigger[2];   /* [IWL_IMG_*] */
 	unsigned int ver;           /* ucode API version from the header */
 	char human[24];
@@ -111,6 +112,9 @@ unsigned int iwl_txq_wptr(int q);
 
 /* Firmware section data (for the NVM/PHY-DB helpers): returns the image. */
 const unsigned char *iwl_fw_data(unsigned int *size);
+/* 8000 family: the CPU2 paging CSS + image of `img`; -1 = no paging. */
+int iwl_fw_paging(int img, const unsigned char **css, unsigned int *css_len,
+		  const unsigned char **pg, unsigned int *pg_len);
 
 /* Byte helpers (`rep movsb/stosb`; the kernel has no libc). */
 void iwl_memcpy(void *dst, const void *src, unsigned int n);