Jelajahi Sumber

Add Intel 6200/6300 WiFi (iwlwifi DVM) for the ThinkPad X201

The X201's Centrino card (a 6300, 8086:4238, on the test machine) runs the
older iwlwifi DVM firmware instead of the 7265D's MVM firmware.  Share
the PCIe transport and wifi.c between both and add a DVM firmware layer.

- iwl_trans.c: per-family descriptor (fam_7000/fam_6000): queue count,
  command queue/FIFO, header size, byte-count units, SCD chain-ext
  workaround, shadow registers, firmware path and the pre-TLV v2 .ucode
  format; transport-programmed AC queues (iwl_txq_enable_fifo), a NIC
  config hook and iwl_fatal().
- iwl_dvm.c: OTP/EEPROM read (MAC, radio config, crystal calibration,
  regulatory channel tables), INIT image calibration capture and runtime
  replay, RXON commits with station restore and fixed-rate LQ tables,
  TX power, per-band scans over the EEPROM's valid channels, ADD_STA keys,
  TX and the DVM tx_resp layout (status at byte 32).
- iwl_fw.c: dispatch between iwl_mvm.c and iwl_dvm.c by probed family.
- wifi.c: a firmware assert drops WiFi to DOWN so the next scan or
  connect reloads the firmware.
- Makefile: pack iwlwifi-6000-4.ucode next to the 7265D firmware
  (WIFI_FW_7265D / WIFI_FW_6000 override the host search).

Tested on the X201: firmware boot, 2.4 GHz scan, WPA2 connect, DHCP and
ping.  The EEPROM channel scan, crash reload and tx status fix are built
but not yet run on the board.  Docs and AGENTS.md updated.
Johannes Zellner 1 Minggu lalu
induk
melakukan
02ed133120
16 mengubah file dengan 1805 tambahan dan 127 penghapusan
  1. 62 15
      AGENTS.md
  2. 35 21
      Makefile
  3. 1 1
      docs/development.html
  4. 49 12
      docs/drivers.html
  5. 1 1
      docs/index.html
  6. 4 3
      docs/network.html
  7. 1194 0
      iwl_dvm.c
  8. 30 0
      iwl_dvm.h
  9. 90 0
      iwl_fw.c
  10. 24 0
      iwl_fw.h
  11. 250 46
      iwl_trans.c
  12. 22 1
      iwl_trans.h
  13. 1 1
      syscall.h
  14. 2 2
      ucmd_wifi.c
  15. 39 23
      wifi.c
  16. 1 1
      wifi.h

+ 62 - 15
AGENTS.md

@@ -103,9 +103,11 @@ make clean
   firmware does not fit a 1.44 MB floppy.  The kernel itself no longer
   carries the pack; the boot path loads it into RAM and `ramfs_init` takes a
   private copy (`bin/<name>` mounted at `/ramfs`).
-- The WiFi firmware `firmware/iwlwifi-7265D-29.ucode` is decompressed from
-  the host's linux-firmware (`WIFI_FW` overrides the search; `zstd` needed for
-  `.zst`).  Without it the build prints a note and packs no firmware.
+- The WiFi firmware `firmware/iwlwifi-7265D-29.ucode` (Chromebook) and
+  `firmware/iwlwifi-6000-4.ucode` (ThinkPad X201) are decompressed from the
+  host's linux-firmware (`WIFI_FW_7265D` / `WIFI_FW_6000` override the
+  search; `zstd` needed for `.zst`).  A missing file only prints a note and
+  leaves that card without firmware.
 - `root.img` is a second FAT12 floppy holding the disk fallback copies of the
   browser/gallery (`BROWSER`, `GALLERY`) and its `DEMO.HTM`/`JS.HTM` test
   pages plus `PIC.BMP`, and a few test files; it requires `mtools` to build.
@@ -704,6 +706,44 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   There is no QEMU model: test on the Chromebook over `make net-dev` with
   the RNDIS phone/ASIX dongle as the management link and `make netmon` for
   the `iwl:`/`wifi:` trail.
+- **WiFi (Intel 6200/6300, the ThinkPad X201)**: the same transport and
+  `wifi.c` drive the 6000 family through `iwl_dvm.c/h` (Linux iwldvm,
+  `iwlwifi-6000-4.ucode`, API 4).  `iwl_fw.c/h` dispatches every firmware
+  call to `iwl_mvm.c` or `iwl_dvm.c` by the probed family (`iwl_is_dvm()`).
+  `iwl_trans.c` keeps per-family parameters in `struct iwl_family`
+  (`fam_7000`/`fam_6000`): the 6000 family has 20 scheduler queues, the
+  command queue on 4 (FIFO 7), 4-byte command headers, a byte-count table in
+  bytes, the SCD chain-extension workaround, no shadow registers and the
+  pre-TLV v2 `.ucode` (inst/data sections loaded at `0x0`/`0x800000`).  The
+  DVM AC queues 0..3 (VO/VI/BE/BK, FIFOs 3/2/1/0) are programmed by the
+  transport (`iwl_txq_enable_fifo()`), not by a firmware command.  PCI IDs:
+  `8086:4239`/`422c` = 6200 (`6000i`, antennas B+C, 2x2 IPA radio SKU bit in
+  `CSR_GP_DRIVER_REG`), `4238`/`422b` = 6300 (`6000`, antennas from the
+  EEPROM).  `iwl_dvm.c`: the host reads the 2 KB OTP through
+  `CSR_EEPROM_REG` (MAC at word 0x15, radio config at 0x48, crystal
+  calibration at 0x128 behind the calibration link 0x67), `nic_config()`
+  runs from the transport between APM init and ring setup; INIT image
+  (ALIVE, AC queues, WiMAX coex off, crystal calibration,
+  `CALIBRATION_CFG_CMD`, `CALIBRATION_RES_NOTIFICATION`s stored by op code
+  until `CALIBRATION_COMPLETE`), runtime image (stored results replayed as
+  `REPLY_PHY_CALIBRATION_CMD`, DC calibration, TX antennas, RXON, TX power,
+  CAM `POWER_TABLE_CMD`).  A full RXON commit clears the association first,
+  which wipes the firmware station table, so the broadcast station 15 and
+  the AP station 0 are re-added with fixed-rate `LINK_QUALITY` tables after
+  every unassociated RXON, and every retune is followed by
+  `REPLY_TX_POWER_DBM_CMD` (15 dBm).  Association is `REPLY_RXON_TIMING`,
+  `REPLY_QOS_PARAM`, then RXON with `RXON_FILTER_ASSOC`.  Scans are one
+  `REPLY_SCAN_CMD` per band (2.4 GHz, then 5 GHz, kicked from the poll path
+  because a synchronous command must not run inside the RX handler) over
+  the channels the EEPROM regulatory tables mark valid (bands at 0x08,
+  0x42, 0x5c, 0x74 behind link 0x66); probes only where a channel is ACTIVE
+  and not RADAR.  On the X201's 6300 the earlier fixed 5 GHz list made the
+  firmware SYSASSERT.  Any firmware assert (`CSR_INT` SW_ERR) now drops
+  `wifi.c` to DOWN (`iwl_fatal()`), so the next scan/connect reloads the
+  firmware instead of timing out forever.  Keys are `REPLY_ADD_STA` in
+  modify mode on the AP station.  RX is the same `RX_PHY` + `RX_MPDU` pair
+  as the 7265D (RSSI from the AGC/in-band fields, `IWLAGN_RSSI_OFFSET` 44),
+  so the software CCMP fallback covers both.
 - **Hot-reload (kexec)**: `kexec.c/h`, `kexec_tramp.S`, `entry.S`, and the
   host-side `kexec_send.c` — reload the kernel over serial without rebooting
   (C-light: reuses the current framebuffer, re-runs `kernel_main`).
@@ -1807,11 +1847,12 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
    `rep movsb`, so the cap is `PACK_MAX` 2 MB (raised from 1 MB for the WiFi
    firmware).  The browser and
    its ring-3 dependencies are compiled with function sections and linked
-   with `--gc-sections`; the current full pack with the UI fonts, the
-   1,036,312-byte WiFi firmware and `install/kernel.bin` is ~1.26 MiB gzip
-   (~1.33 MB), inflating to ~2.6 MB, which adds about half a second to the
-   boot; the floppy lite pack is ~680 KiB gzip and deliberately omits
-   `install/kernel.bin`.  `libdeflate-gzip -12` is still preferred.  Over
+   with `--gc-sections`; the current full pack with the UI fonts, both
+   WiFi firmwares (7265D 1,036,312 bytes, ~442 KiB gzip; 6000 454,608 bytes,
+   ~204 KiB gzip) and `install/kernel.bin` is ~1.72 MiB gzip (1,799,973
+   bytes, ~290 KB under the cap), inflating to ~3.6 MB, which adds about
+   half a second to the boot; the floppy lite pack is ~930 KiB gzip and
+   deliberately omits the firmware and `install/kernel.bin`.  `libdeflate-gzip -12` is still preferred.  Over
    115200 serial a raw `cmds-dev` pack (2.6 MB) now takes about three
    minutes; use `net-cmds`.
 9. SMP is **ACPI/MADT only**: no Intel MP-table fallback, so a Pentium II SMP
@@ -1871,8 +1912,8 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     (8 slots x 1 KB), and the FAT listing cache another 5 KB.  The command
     pack is out of the kernel now; after the WiFi/netmenu/install code and the
     per-connection TCP queues moved to the frame allocator, `_end` is
-    ~0x80180, ~64 KB below the `0x90000` wall, and the remaining limit is
-    kernel code/buffers only.
+    ~0x82320 (with the 6200/6300 DVM layer), ~56 KB below the `0x90000`
+    wall, and the remaining limit is kernel code/buffers only.
 
 22. Browser limits: JavaScript runs inline and external classic scripts on
     QuickJS (ES2025) with the DOM surface described above (creation/mutation/selectors/
@@ -2123,9 +2164,15 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     messages over 4 KB are truncated, history holds 240 messages, times are
     UTC and text is Latin-1.  Network calls block the UI for their duration.
 
-35. WiFi limits (`iwl_trans.c`, `iwl_mvm.c`, `wifi.c`): Intel 7265 rev D and
-    3165 only (one firmware, `iwlwifi-7265D-29`); a non-D 7265 is logged and
-    will likely fail.  Open networks and WPA2-PSK with CCMP pairwise *and*
+35. WiFi limits (`iwl_trans.c`, `iwl_mvm.c`, `iwl_dvm.c`, `wifi.c`): Intel
+    7265 rev D/3165 (`iwlwifi-7265D-29`) 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
+    hardware in the loop at first; on the X201 (a 6300, `8086:4238`) the
+    firmware boots and the 2.4 GHz scan works, while the 5 GHz scan and
+    connect are still being brought up.  It has no sensitivity, chain-noise
+    or temperature calibration and a fixed 15 dBm TX power.  Open networks and WPA2-PSK with CCMP pairwise *and*
     group only: no WPA3/SAE, PMF/802.11w, 802.1X, TKIP, WEP or hidden-SSID
     connects.  Legacy rates only (12 Mb/s data, no LQ/rate scaling, no
     HT/VHT, no aggregation, non-QoS association), no power save, roaming,
@@ -2142,8 +2189,8 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     window yet and uses a byte-oriented AES-CCM per frame, so high RX
     throughput is CPU-bound.  The driver was written against the Linux iwlwifi
     sources without hardware in the loop; expect bring-up debugging on the
-    Chromebook.  The kernel budget is tight: WiFi added ~20 KB, `_end` is
-    ~0x80180 (~64 KB below the `0x90000` wall).
+    Chromebook.  The kernel budget is tight: WiFi added ~28 KB with both
+    firmware layers, `_end` is ~0x82320 (~56 KB below the `0x90000` wall).
 
 36. Network menu limits (`ucmd_netmenu.c`): building the device list probes
     every driver, so opening the menu on a machine with an unconfigured USB

File diff ditekan karena terlalu besar
+ 35 - 21
Makefile


+ 1 - 1
docs/development.html

@@ -80,7 +80,7 @@
 			<li><strong>User commands.</strong> Linked at <code>0x40000000</code> with <code>ucmd.ld</code>, stripped, and packed as <code>bin/&lt;name&gt;</code>.</li>
 			<li><strong>UEFI.</strong> <code>x86_64-w64-mingw32-gcc</code> builds <code>BOOTX64.EFI</code>; <code>make all</code> does not require it.</li>
 			<li><strong>Images.</strong> <code>mtools</code> builds <code>root.img</code> and the ESP.</li>
-			<li><strong>WiFi firmware.</strong> The pack includes <code>firmware/iwlwifi-7265D-29.ucode</code>, decompressed with <code>zstd</code> from the host's linux-firmware (<code>WIFI_FW=/path/to/file[.zst]</code> overrides the search). Without it the build prints a note and packs no firmware; the floppy images always use the firmware-less <code>cmds-lite.pack</code>.</li>
+			<li><strong>WiFi firmware.</strong> The pack includes <code>firmware/iwlwifi-7265D-29.ucode</code> (Chromebook) and <code>firmware/iwlwifi-6000-4.ucode</code> (X201), decompressed with <code>zstd</code> from the host's linux-firmware (<code>WIFI_FW_7265D=</code> / <code>WIFI_FW_6000=/path/to/file[.zst]</code> override the search). A missing file only prints a note and leaves that card without firmware; the floppy images always use the firmware-less <code>cmds-lite.pack</code>.</li>
 		</ul>
 	</section>
 

+ 49 - 12
docs/drivers.html

@@ -55,7 +55,7 @@
 			<li><a href="#pci">PCI &amp; discovery</a></li>
 			<li><a href="#storage">Storage</a></li>
 			<li><a href="#usb">USB stack</a></li>
-			<li><a href="#wifi">WiFi (Intel 7265D/3165)</a></li>
+			<li><a href="#wifi">WiFi (Intel 7265D/3165, 6200/6300)</a></li>
 			<li><a href="#hid">Input</a></li>
 			<li><a href="#serial">Serial</a></li>
 			<li><a href="#sensors">Sensors &amp; power</a></li>
@@ -85,7 +85,7 @@
 					<tr><td>eMMC</td><td><span class="file">sdhci.c</span></td><td>Intel Braswell SDHCI, PCI <code>00:10.0</code> (<code>8086:2294</code>)</td><td>Polled PIO, 1-bit/25 MHz; no DMA/IRQ</td></tr>
 					<tr><td>USB</td><td><span class="file">usb.c</span> + <span class="file">uhci.c</span> <span class="file">ohci.c</span> <span class="file">ehci.c</span> <span class="file">xhci.c</span></td><td>PCI I/O ports or MMIO</td><td>Polled; hotplug watcher in the WM loop</td></tr>
 					<tr><td>Network</td><td><span class="file">e1000e.c</span> <span class="file">r8168.c</span> <span class="file">ne2000.c</span> <span class="file">asix.c</span> <span class="file">rndis.c</span></td><td>PCI or USB</td><td>Polled, one active receiver</td></tr>
-					<tr><td>WiFi</td><td><span class="file">iwl_trans.c</span> <span class="file">iwl_mvm.c</span> <span class="file">wifi.c</span></td><td>PCIe, Intel 7265D/3165 (<code>8086:095a/095b/3165/3166</code>)</td><td>Polled RX ring; firmware from <code>/ramfs/firmware</code>, loaded on first use</td></tr>
+					<tr><td>WiFi</td><td><span class="file">iwl_trans.c</span> <span class="file">iwl_mvm.c</span> <span class="file">iwl_dvm.c</span> <span class="file">wifi.c</span></td><td>PCIe, Intel 7265D/3165 (<code>8086:095a/095b/3165/3166</code>) and 6200/6300 (<code>8086:4239/422c</code>, <code>4238/422b</code>)</td><td>Polled RX ring; firmware from <code>/ramfs/firmware</code>, loaded on first use</td></tr>
 					<tr><td>PS/2</td><td><span class="file">mouse.c</span>, <span class="file">io.c</span></td><td>i8042</td><td>IRQ 1 keyboard, IRQ 12 mouse; polling fallback</td></tr>
 					<tr><td>Touchpad</td><td><span class="file">i2c.c</span>, <span class="file">touchpad.c</span>, <span class="file">touchpad_gesture.c</span></td><td>LPSS DesignWare I2C, slave <code>0x15</code></td><td>Polled input register every 25 ms; software tap and two-finger scroll gestures; no GPIO interrupt driver</td></tr>
 					<tr><td>Serial</td><td><span class="file">serial.c</span></td><td>16550 UART, COM1</td><td>IRQ 4 ring buffer + polled transmitter</td></tr>
@@ -341,12 +341,18 @@
 	</section>
 
 	<section id="wifi">
-		<h2>WiFi (Intel 7265D/3165)</h2>
+		<h2>WiFi (Intel 7265D/3165, 6200/6300)</h2>
 		<p>
-			The HP Chromebook (Braswell) has no wired NIC; its built-in Intel
-			Wireless-AC 7265 rev D or 3165 is driven in three layers, all
-			polled. The kernel part is about 20 KB of code; every ring and
-			buffer is page-allocated so nothing new lands in the kernel BSS.
+			Two Intel generations share one PCIe transport. The HP Chromebook's
+			Wireless-AC 7265 rev D or 3165 runs the newer <em>MVM</em> firmware
+			(<span class="file">iwl_mvm.c</span>); the ThinkPad X201's Centrino
+			Advanced-N 6200 (or Ultimate-N 6300) runs the older <em>DVM</em>
+			firmware (<span class="file">iwl_dvm.c</span>).
+			<span class="file">iwl_fw.c</span> picks the layer from the PCI
+			probe, so <span class="file">wifi.c</span> and the
+			<code>wifi</code> command are the same for both. Everything is
+			polled; every ring and buffer is page-allocated so nothing big lands
+			in the kernel BSS.
 		</p>
 		<figure class="figure">
 			<svg viewBox="0 0 920 300" role="img" aria-labelledby="wifi-title wifi-desc">
@@ -366,7 +372,7 @@
 				<text class="svg-sub" x="60" y="152">auth/assoc · 802.11 ↔ Ethernet (LLC/SNAP, CCMP header) · EAPOL queue · SYS_WIFI</text>
 
 				<rect class="svg-box" x="40" y="182" width="840" height="44" rx="9"/>
-				<text class="svg-text" x="60" y="209">iwl_mvm.c — firmware commands: INIT/RT image, NVM, scan, contexts, stations, keys</text>
+				<text class="svg-text" x="60" y="209">iwl_mvm.c (7265D) · iwl_dvm.c (6200/6300) — firmware commands, via iwl_fw.c</text>
 
 				<rect class="svg-box green" x="40" y="246" width="840" height="44" rx="9"/>
 				<text class="svg-text" x="60" y="273">iwl_trans.c — CSR/PRPH access, TFD + RX rings, firmware section DMA (PCIe)</text>
@@ -384,7 +390,8 @@
 				frames and hands the TK/GTK to the firmware, which does CCMP.
 				Sources: <span class="file">ucmd_wifi.c</span>,
 				<span class="file">wpa.c</span>, <span class="file">wifi.c</span>,
-				<span class="file">iwl_mvm.c</span>, <span class="file">iwl_trans.c</span>.
+				<span class="file">iwl_fw.c</span>, <span class="file">iwl_mvm.c</span>,
+				<span class="file">iwl_dvm.c</span>, <span class="file">iwl_trans.c</span>.
 			</figcaption>
 		</figure>
 		<ul>
@@ -396,6 +403,34 @@
 			<li><strong>Bring-up on first use.</strong> The boot probe only finds the PCI function. The firmware is loaded by the first <code>wifi</code> command, so boot time and RAM do not change when WiFi is unused. The netdev reports <code>link_up() = 0</code> until it is connected, so the boot DHCP is skipped.</li>
 			<li><strong>kexec.</strong> <code>netdev_shutdown()</code> always stops the card through <code>wifi_shutdown()</code>, even when it is not the active netdev, because its RX ring would keep writing into pages the next kernel reuses.</li>
 		</ul>
+		<h3>6200/6300: the DVM firmware</h3>
+		<p>
+			The transport differences live in one per-family descriptor
+			(<code>fam_7000</code>/<code>fam_6000</code> in
+			<span class="file">iwl_trans.c</span>):
+		</p>
+		<div class="table-wrap">
+			<table>
+				<thead>
+					<tr><th>Parameter</th><th>7265D/3165 (MVM)</th><th>6200/6300 (DVM)</th></tr>
+				</thead>
+				<tbody>
+					<tr><td>Firmware</td><td><code>iwlwifi-7265D-29.ucode</code> (TLV)</td><td><code>iwlwifi-6000-4.ucode</code> (v2 header: inst/data sections at <code>0x0</code>/<code>0x800000</code>)</td></tr>
+					<tr><td>Scheduler queues</td><td>31</td><td>20</td></tr>
+					<tr><td>Command queue / FIFO</td><td>0 / 7</td><td>4 / 7</td></tr>
+					<tr><td>Data queues</td><td>aux 1, BSS 4 (configured by firmware, <code>SCD_QUEUE_CFG</code>)</td><td>VO 0 (management), VI 1, BE 2 (data), BK 3 (configured by the transport)</td></tr>
+					<tr><td>Command header</td><td>8-byte wide (group 1)</td><td>4-byte</td></tr>
+					<tr><td>Byte-count table</td><td>dwords</td><td>bytes</td></tr>
+					<tr><td>MAC address</td><td>NVM via <code>NVM_ACCESS_CMD</code></td><td>OTP read by the host through <code>CSR_EEPROM_REG</code></td></tr>
+				</tbody>
+			</table>
+		</div>
+		<ul>
+			<li><strong>Bring-up.</strong> The host reads the 2 KB OTP (MAC at word 0x15, radio config at 0x48, crystal calibration through the calibration link), writes the radio SKU bits during NIC init, then runs the INIT image: <code>CALIBRATION_CFG_CMD</code> and every <code>CALIBRATION_RES_NOTIFICATION</code> stored by op code until <code>CALIBRATION_COMPLETE</code>. The runtime image gets the stored results back as <code>REPLY_PHY_CALIBRATION_CMD</code>, DC calibration, TX antennas, an RXON, TX power and a CAM power table.</li>
+			<li><strong>RXON.</strong> DVM has no MAC/PHY contexts: one <code>REPLY_RXON</code> carries channel, BSSID, filters and association. A full RXON first clears the association, which wipes the firmware's station table, so the broadcast station (15) and the AP station (0) are re-added with their fixed-rate <code>LINK_QUALITY</code> tables, and a new TX power command follows every retune.</li>
+			<li><strong>Scan.</strong> One <code>REPLY_SCAN_CMD</code> per band: 2.4 GHz, then 5 GHz after <code>SCAN_COMPLETE_NOTIFICATION</code>. Only channels the EEPROM regulatory tables mark valid are scanned, and probes are only sent where they are marked active and not radar. A firmware assert makes the next scan or connect reload the firmware instead of failing until reboot.</li>
+			<li><strong>Keys.</strong> <code>REPLY_ADD_STA</code> in modify mode on the AP station (pairwise offset 0, group offset 1). RX frames are the same <code>RX_PHY</code> + <code>RX_MPDU</code> pair as on the 7265D, so the software CCMP fallback in <span class="file">wifi.c</span> covers both cards. The 6200 transmits on antenna B (its <code>ANT_BC</code> configuration).</li>
+		</ul>
 	</section>
 
 	<section id="hid">
@@ -578,7 +613,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. Battery/AC is polled by the WM once a second.</li>
-			<li><strong>WiFi.</strong> Intel 7265 rev D and 3165 only (the 7265D firmware); 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) 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>Suspend.</strong> There is no S0ix/suspend path; package C-states and the EC sleep handshake remain firmware-managed.</li>
 		</ul>
 	</section>
@@ -595,8 +630,10 @@
 			<li><code>uhci.c</code>, <code>ohci.c</code>, <code>ehci.c</code>, <code>xhci.c</code></li>
 			<li><code>usbmsc.c</code>, <code>usbmsc.h</code> — USB BOT/SCSI mass storage</li>
 			<li><code>rndis.c</code>, <code>rndis.h</code> — USB RNDIS tethering</li>
-			<li><code>iwl_trans.c</code>, <code>iwl_trans.h</code> — Intel 7265D/3165 PCIe transport</li>
-			<li><code>iwl_mvm.c</code>, <code>iwl_mvm.h</code> — WiFi firmware commands</li>
+			<li><code>iwl_trans.c</code>, <code>iwl_trans.h</code> — Intel WiFi PCIe transport (7000 and 6000 families)</li>
+			<li><code>iwl_mvm.c</code>, <code>iwl_mvm.h</code> — 7265D/3165 firmware commands (MVM)</li>
+			<li><code>iwl_dvm.c</code>, <code>iwl_dvm.h</code> — 6200/6300 firmware commands (DVM)</li>
+			<li><code>iwl_fw.c</code>, <code>iwl_fw.h</code> — firmware-layer dispatch</li>
 			<li><code>wifi.c</code>, <code>wifi.h</code> — 802.11 station, <code>wifi</code> netdev, <code>SYS_WIFI</code></li>
 			<li><code>ccmp.c</code>, <code>ccmp.h</code> — software CCMP RX fallback (AES-CCM)</li>
 			<li><code>install.c</code> — live-image clone installer</li>

+ 1 - 1
docs/index.html

@@ -222,7 +222,7 @@
 			</a>
 			<a class="card" href="drivers.html#wifi">
 				<h3>WiFi</h3>
-				<p>Intel 7265D/3165 on the Chromebook: PCIe transport, firmware from the command pack, LMAC scan, open and WPA2-PSK/CCMP with the handshake in ring 3.</p>
+				<p>Intel 7265D/3165 (Chromebook, MVM firmware) and 6200/6300 (ThinkPad X201, DVM firmware) on one PCIe transport, firmware from the command pack, open and WPA2-PSK/CCMP with the handshake in ring 3.</p>
 				<span class="card-tag">drivers.html#wifi</span>
 			</a>
 			<a class="card" href="network.html#chat">

+ 4 - 3
docs/network.html

@@ -170,7 +170,8 @@
 		</p>
 		<p>
 			<span class="file">wifi.c</span> is the built-in WiFi of the
-			Chromebook (Intel 7265D/3165, see the
+			Chromebook (Intel 7265D/3165) and of the ThinkPad X201 (Intel
+			6200/6300), see the
 			<a href="drivers.html#wifi">driver page</a>). It is last in the
 			registry, so the boot probe only makes it active when nothing
 			wired is present (a later <code>wifi connect</code> can still select
@@ -214,7 +215,7 @@
 					<tr><td><span class="file">ne2000.c</span></td><td>RTL8029</td><td>ISA / QEMU PCI</td><td>Simple DP8390 path used by <code>make run-net</code>.</td></tr>
 					<tr><td><span class="file">asix.c</span></td><td>AX88772</td><td>USB bulk</td><td>Runs over the USB core; usable on EHCI/xHCI dongles.</td></tr>
 					<tr><td><span class="file">rndis.c</span></td><td>Android USB tethering, QEMU <code>usb-net</code></td><td>USB control + bulk</td><td>RNDIS INIT/QUERY/packet filter; presents the phone's tethering link as an Ethernet netdev.</td></tr>
-					<tr><td><span class="file">wifi.c</span></td><td>Intel 7265D / 3165 (Chromebook)</td><td>PCIe (firmware)</td><td>Open and WPA2-PSK/CCMP; firmware loaded on first use; link down until <code>wifi connect</code>.</td></tr>
+					<tr><td><span class="file">wifi.c</span></td><td>Intel 7265D / 3165 (Chromebook), 6200 / 6300 (X201)</td><td>PCIe (firmware)</td><td>Open and WPA2-PSK/CCMP; firmware loaded on first use; link down until <code>wifi connect</code>.</td></tr>
 				</tbody>
 			</table>
 		</div>
@@ -474,7 +475,7 @@
 		<ul class="filelist">
 			<li><code>netdev.c</code>, <code>netdev.h</code> — registry</li>
 			<li><code>e1000e.c</code>, <code>r8168.c</code>, <code>ne2000.c</code>, <code>asix.c</code>, <code>rndis.c</code></li>
-			<li><code>wifi.c</code>, <code>iwl_mvm.c</code>, <code>iwl_trans.c</code> — Intel 7265D/3165 WiFi</li>
+			<li><code>wifi.c</code>, <code>iwl_fw.c</code>, <code>iwl_mvm.c</code>, <code>iwl_dvm.c</code>, <code>iwl_trans.c</code> — Intel 7265D/3165 and 6200/6300 WiFi</li>
 			<li><code>wpa.c</code>, <code>wpa_crypto.c</code>, <code>ucmd_wifi.c</code> — WPA2-PSK supplicant and the <code>wifi</code> command (<code>make test-wpa</code>)</li>
 			<li><code>ucmd_netmenu.c</code>, <code>wifi_cfg.h</code> — top-bar network menu and its staged WiFi connect request</li>
 			<li><code>net.c</code>, <code>net.h</code> — ARP cache/ICMP/UDP/IP</li>

+ 1194 - 0
iwl_dvm.c

@@ -0,0 +1,1194 @@
+/* Intel 6200/6300 firmware layer (iwlwifi DVM): see iwl_dvm.h.
+ *
+ * Follows Linux iwldvm for iwlwifi-6000-4.ucode (API 4):
+ *
+ *   EEPROM/OTP is read by the host (MAC address, radio config, crystal
+ *     calibration), NIC config writes the radio SKU bits before the rings.
+ *   INIT image: ALIVE -> AC queues -> WiMAX coex off -> crystal calibration
+ *     -> CALIBRATION_CFG_CMD; CALIBRATION_RES_NOTIFICATIONs are stored by op
+ *     code until CALIBRATION_COMPLETE_NOTIFICATION, then the device stops.
+ *   runtime image: ALIVE -> AC queues -> coex -> stored calibration results
+ *     (REPLY_PHY_CALIBRATION_CMD) -> DC calibration -> TX antennas ->
+ *     unassociated RXON (+ broadcast station and its LQ) -> TX power ->
+ *     CAM power table.
+ *
+ * A full RXON commit always clears the association first, which wipes the
+ * firmware's station table, so the broadcast station (and the AP station
+ * once added) are re-added after it, as iwl_restore_stations() does.
+ * Legacy rates only (no HT, no rate scaling): an LQ table holds one fixed
+ * rate.  RX frames arrive as REPLY_RX_PHY_CMD + REPLY_RX_MPDU_CMD, the same
+ * as the 7265D's legacy path, and go to wifi.c unchanged. */
+
+#include "iwl_dvm.h"
+#include "iwl_mvm.h"       /* wifi_rx_frame/wifi_scan_done, IWL_RX_* */
+#include "iwl_trans.h"
+#include "mm.h"
+#include "serial.h"
+
+/* ---- command ids (dvm/commands.h) --------------------------------------- */
+#define REPLY_ALIVE                  0x01
+#define REPLY_ERROR                  0x02
+#define REPLY_RXON                   0x10
+#define REPLY_QOS_PARAM              0x13
+#define REPLY_RXON_TIMING            0x14
+#define REPLY_ADD_STA                0x18
+#define REPLY_REMOVE_STA             0x19
+#define REPLY_TX                     0x1c
+#define REPLY_TX_LINK_QUALITY_CMD    0x4e
+#define COEX_PRIORITY_TABLE_CMD      0x5a
+#define CALIBRATION_CFG_CMD          0x65
+#define CALIBRATION_RES_NOTIFICATION 0x66
+#define CALIBRATION_COMPLETE_NOTIF   0x67
+#define POWER_TABLE_CMD              0x77
+#define REPLY_SCAN_CMD               0x80
+#define SCAN_COMPLETE_NOTIFICATION   0x84
+#define REPLY_TX_POWER_DBM_CMD       0x95
+#define TX_ANT_CONFIGURATION_CMD     0x98
+#define REPLY_PHY_CALIBRATION_CMD    0xb0
+#define REPLY_RX_PHY_CMD             0xc0
+#define REPLY_RX_MPDU_CMD            0xc1
+
+#define IWL_AP_ID            0
+#define IWLAGN_BROADCAST_ID  15
+
+#define RXON_FLG_BAND_24G    (1u << 0)
+#define RXON_FLG_AUTO_DETECT (1u << 2)
+#define RXON_FLG_SHORT_SLOT  (1u << 4)
+#define RXON_FLG_TSF2HOST    (1u << 15)
+#define RXON_FILTER_ACCEPT_GRP (1u << 2)
+#define RXON_FILTER_ASSOC    (1u << 5)
+#define RXON_DEV_TYPE_ESS    3
+
+#define STA_CONTROL_MODIFY   0x01
+#define STA_MODIFY_KEY_MASK  0x01
+#define STA_KEY_FLG_CCMP     0x0002
+#define STA_KEY_FLG_MAP_KEY  0x0008
+#define STA_KEY_FLG_INVALID  0x0800
+#define STA_KEY_MULTICAST    0x4000
+
+#define RATE_CCK       (1u << 9)
+#define RATE_ANT_POS   14
+#define PLCP_1M        10
+#define PLCP_6M        13
+#define PLCP_12M       5
+
+#define TX_FLG_ACK       (1u << 3)
+#define TX_FLG_SEQ_CTL   (1u << 13)
+#define TX_SEC_CCM       0x02
+
+#define IWL_CALIB_INIT_CFG_ALL  0x5fu   /* RX_BB|DC|LO|TX_IQ|RX_IQ|CRYSTAL */
+#define IWL_CALIB_RT_CFG_ALL    0x5dfu  /* + TEMPERATURE|PAPD|TX_PWR */
+#define IWL_CALIB_CFG_DC        (1u << 1)
+#define IWL_CALIB_SEND_COMPLETE (1u << 0)
+#define IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD 15
+
+#define IWLAGN_RSSI_OFFSET 44
+
+/* ---- wire structures (packed, little endian) --------------------------- */
+#define PACKED __attribute__((packed))
+
+struct alive_resp {                  /* struct iwl_alive_resp */
+	unsigned char ucode_minor, ucode_major;
+	unsigned short res1;
+	unsigned char sw_rev[8];
+	unsigned char ver_type, ver_subtype;
+	unsigned short res2;
+	unsigned int log_event_table_ptr, error_event_table_ptr;
+	unsigned int timestamp, is_valid;
+} PACKED;
+
+struct rxon_cmd {                    /* struct iwl_rxon_cmd */
+	unsigned char node_addr[6];
+	unsigned short res1;
+	unsigned char bssid_addr[6];
+	unsigned short res2;
+	unsigned char wlap_bssid_addr[6];
+	unsigned short res3;
+	unsigned char dev_type, air_propagation;
+	unsigned short rx_chain;
+	unsigned char ofdm_basic_rates, cck_basic_rates;
+	unsigned short assoc_id;
+	unsigned int flags, filter_flags;
+	unsigned short channel;
+	unsigned char ht_single, ht_dual, ht_triple, res5;
+	unsigned short acquisition_data, res6;
+} PACKED;
+
+struct rxon_timing {                 /* struct iwl_rxon_time_cmd */
+	unsigned int timestamp_lo, timestamp_hi;
+	unsigned short beacon_interval, atim_window;
+	unsigned int beacon_init_val;
+	unsigned short listen_interval;
+	unsigned char dtim_period, delta_cp_bss_tbtts;
+} PACKED;
+
+struct keyinfo {                     /* struct iwl_keyinfo */
+	unsigned short key_flags;
+	unsigned char tkip_rx_tsc_byte2, res1;
+	unsigned short tkip_rx_ttak[5];
+	unsigned char key_offset, res2;
+	unsigned char key[16];
+	unsigned int tx_seq[2], mic_rx[2], mic_tx[2];
+} PACKED;
+
+struct addsta_cmd {                  /* struct iwl_addsta_cmd */
+	unsigned char mode, res[3];
+	unsigned char addr[6];
+	unsigned short res1;
+	unsigned char sta_id, modify_mask;
+	unsigned short res2;
+	struct keyinfo key;
+	unsigned int station_flags, station_flags_msk;
+	unsigned short tid_disable_tx, legacy_res;
+	unsigned char add_ba_tid, remove_ba_tid;
+	unsigned short add_ba_ssn, sleep_tx_count, res3;
+} PACKED;
+
+struct lq_cmd {                      /* struct iwl_link_quality_cmd */
+	unsigned char sta_id, res1;
+	unsigned short control;
+	unsigned char flags, mimo_delimiter, single_ant, dual_ant;
+	unsigned char start_rate_index[4];
+	unsigned short agg_time_limit;
+	unsigned char agg_dis_start_th, agg_frame_cnt_limit;
+	unsigned int agg_res;
+	unsigned int rs_table[16];
+	unsigned int res2;
+} PACKED;
+
+struct tx_cmd {                      /* struct iwl_tx_cmd */
+	unsigned short len, next_frame_len;
+	unsigned int tx_flags;
+	unsigned char try_cnt, btkill_cnt;
+	unsigned short scratch_res;
+	unsigned int rate_n_flags;
+	unsigned char sta_id, sec_ctl, initial_rate_index, res;
+	unsigned char key[16];
+	unsigned short next_frame_flags, res2;
+	unsigned int life_time, dram_lsb_ptr;
+	unsigned char dram_msb_ptr, rts_retry_limit, data_retry_limit, tid_tspec;
+	unsigned short pm_frame_timeout, driver_txop;
+} PACKED;
+
+struct scan_cmd {                    /* struct iwl_scan_cmd (fixed part) */
+	unsigned short len;
+	unsigned char scan_flags, channel_count;
+	unsigned short quiet_time, quiet_plcp_th, good_crc_th, rx_chain;
+	unsigned int max_out_time, suspend_time, flags, filter_flags;
+	struct tx_cmd tx;
+	struct { unsigned char id, len, ssid[32]; } direct_scan[20];
+} PACKED;
+
+struct scan_chan {                   /* struct iwl_scan_channel */
+	unsigned int type;
+	unsigned short channel;
+	unsigned char tx_gain, dsp_atten;
+	unsigned short active_dwell, passive_dwell;
+} PACKED;
+
+struct calib_cfg_elmnt {
+	unsigned int is_enable, start, send_res, apply_res, res;
+} PACKED;
+
+struct calib_cfg_cmd {               /* struct iwl_calib_cfg_cmd */
+	struct calib_cfg_elmnt ucd_once, ucd_perd;
+	unsigned int ucd_flags;
+	struct calib_cfg_elmnt drv_once, drv_perd;
+	unsigned int drv_flags;
+	unsigned int res1;
+} PACKED;
+
+typedef char dchk1[sizeof(struct rxon_cmd) == 50 ? 1 : -1];
+typedef char dchk2[sizeof(struct addsta_cmd) == 92 ? 1 : -1];
+typedef char dchk3[sizeof(struct lq_cmd) == 88 ? 1 : -1];
+typedef char dchk4[sizeof(struct tx_cmd) == 56 ? 1 : -1];
+typedef char dchk5[sizeof(struct scan_cmd) == 764 ? 1 : -1];
+typedef char dchk6[sizeof(struct alive_resp) == 32 ? 1 : -1];
+typedef char dchk7[sizeof(struct rxon_timing) == 20 ? 1 : -1];
+
+/* ---- state ------------------------------------------------------------- */
+#define EEPROM_SIZE   2048            /* OTP_LOW_IMAGE_SIZE_2K */
+#define CALIB_PAGES   4
+
+static struct {
+	int up;
+	const char *state;
+	unsigned char mac[6];
+	unsigned char bssid[6];
+	unsigned int chan;
+	unsigned int valid_tx_ant, valid_rx_ant, first_tx_ant;
+	unsigned int radio_cfg;
+	unsigned char xtal[2];
+	int alive, alive_ok, calib_done;
+	unsigned int err_table;
+	unsigned char *calib;          /* [op u8][pad][len u16][data...] */
+	unsigned int calib_len;
+	unsigned char *eeprom;
+	unsigned char *scratch;        /* 8 KB command scratch */
+	struct rxon_cmd rxon;
+	int ap_sta;
+	int assoc;
+	int scanning, scan_band_5, scan_next5;
+	/* scan lists from the EEPROM regulatory tables: channel | 0x100 active */
+	unsigned short ch24[14], ch5[32];
+	unsigned int n24, n5;
+	int last_rssi, last_chan;
+	unsigned char tk[16];
+	int have_tk;
+} D;
+
+static void logs(const char *s)
+{
+	iwl_log(s);
+}
+
+static unsigned int get16(const unsigned char *p)
+{
+	return p[0] | (p[1] << 8);
+}
+
+static unsigned int get32(const unsigned char *p)
+{
+	return p[0] | (p[1] << 8) | (p[2] << 16) | ((unsigned int)p[3] << 24);
+}
+
+static void put16(unsigned char *p, unsigned int v)
+{
+	p[0] = v; p[1] = v >> 8;
+}
+
+static void dump_error_log(void);
+
+static int cmd(unsigned int id, const void *data, unsigned int len)
+{
+	if (iwl_send_cmd(id, data, len, 0, 0) < 0) {
+		iwl_loghex("command failed, id", id);
+		dump_error_log();
+		return -1;
+	}
+	return 0;
+}
+
+/* ---- EEPROM / OTP (iwl-eeprom-read.c) ----------------------------------- */
+#define CSR_HW_IF_CONFIG_REG   0x000
+#define CSR_GP_CNTRL           0x024
+#define CSR_EEPROM_REG         0x02c
+#define CSR_EEPROM_GP          0x030
+#define CSR_OTP_GP_REG         0x034
+#define CSR_GP_DRIVER_REG      0x050
+#define CSR_DBG_LINK_PWR_MGMT  0x250
+#define APMG_PS_CTRL_REG       0x300c
+
+static void set32(unsigned int reg, unsigned int bits)
+{
+	iwl_wr(reg, iwl_rd(reg) | bits);
+}
+
+static int poll32(unsigned int reg, unsigned int bits, unsigned int us)
+{
+	unsigned int t;
+
+	for (t = 0; t < us; t += 5) {
+		if ((iwl_rd(reg) & bits) == bits)
+			return 0;
+		iwl_udelay(5);
+	}
+	return -1;
+}
+
+static int read_eeprom(void)
+{
+	unsigned int gp, otp, addr, i;
+
+	/* Signature: OTP with a good signature (6000 family uses OTP). */
+	gp = iwl_rd(CSR_EEPROM_GP) & 7u;
+	otp = (iwl_rd(CSR_OTP_GP_REG) & 0x00010000u) != 0;
+	if (!(otp ? gp == 1 : (gp == 2 || gp == 4))) {
+		iwl_loghex("bad EEPROM/OTP signature, EEPROM_GP", iwl_rd(CSR_EEPROM_GP));
+		return -1;
+	}
+	/* EEPROM semaphore (CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM). */
+	for (i = 0; i < 1000; i++) {
+		set32(CSR_HW_IF_CONFIG_REG, 0x00200000u);
+		if (poll32(CSR_HW_IF_CONFIG_REG, 0x00200000u, 10) == 0)
+			break;
+	}
+	if (i == 1000) {
+		logs("EEPROM semaphore busy");
+		return -1;
+	}
+	if (otp) {
+		/* iwl_init_otp_access(): MAC clock is up (start_hw), reset the
+		 * OTP block, disable the auto clock gate (shadow RAM). */
+		iwl_wr_prph(APMG_PS_CTRL_REG,
+			    iwl_rd_prph(APMG_PS_CTRL_REG) | 0x04000000u);
+		iwl_udelay(5);
+		iwl_wr_prph(APMG_PS_CTRL_REG,
+			    iwl_rd_prph(APMG_PS_CTRL_REG) & ~0x04000000u);
+		set32(CSR_DBG_LINK_PWR_MGMT, 0x80000000u);
+		iwl_wr(CSR_EEPROM_GP, iwl_rd(CSR_EEPROM_GP) & ~0x00000180u);
+		set32(CSR_OTP_GP_REG, 0x00300000u);   /* ack ECC status bits */
+	}
+	for (addr = 0; addr < EEPROM_SIZE; addr += 2) {
+		unsigned int r;
+
+		iwl_wr(CSR_EEPROM_REG, (addr << 1) & 0xfffcu);
+		if (poll32(CSR_EEPROM_REG, 1u, 5000) < 0) {
+			iwl_loghex("EEPROM read timeout at", addr);
+			goto fail;
+		}
+		r = iwl_rd(CSR_EEPROM_REG);
+		if (otp && (iwl_rd(CSR_OTP_GP_REG) & 0x00200000u)) {
+			set32(CSR_OTP_GP_REG, 0x00200000u);
+			logs("uncorrectable OTP ECC error");
+			goto fail;
+		}
+		D.eeprom[addr] = r >> 16;
+		D.eeprom[addr + 1] = r >> 24;
+	}
+	iwl_wr(CSR_HW_IF_CONFIG_REG, iwl_rd(CSR_HW_IF_CONFIG_REG) & ~0x00200000u);
+	return 0;
+fail:
+	iwl_wr(CSR_HW_IF_CONFIG_REG, iwl_rd(CSR_HW_IF_CONFIG_REG) & ~0x00200000u);
+	return -1;
+}
+
+/* iwl-eeprom-parse.c: direct word offsets, and an indirect address that
+ * adds the calibration section link (EEPROM_LINK_CALIBRATION, 0x67). */
+static const unsigned char *eeprom_at(unsigned int byte_off, int calib)
+{
+	if (calib)
+		byte_off += get16(D.eeprom + 2 * 0x67) << 1;
+	return byte_off + 2 <= EEPROM_SIZE ? D.eeprom + byte_off : 0;
+}
+
+/* EEPROM regulatory channel tables (iwl_init_band_reference(); offsets
+ * EEPROM_REG_BAND_[1345]_CHANNELS behind the regulatory link 0x66): two
+ * bytes per channel, flags (VALID bit 0, ACTIVE bit 3, RADAR bit 4) and the
+ * max power.  Only valid channels are scanned, and probes are only sent
+ * where the table allows active scanning without radar detection. */
+static void parse_channels(void)
+{
+	static const unsigned char b1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+					    12, 13, 14 };
+	static const unsigned char b3[] = { 34, 36, 38, 40, 42, 44, 46, 48, 52,
+					    56, 60, 64 };
+	static const unsigned char b4[] = { 100, 104, 108, 112, 116, 120, 124,
+					    128, 132, 136, 140 };
+	static const unsigned char b5[] = { 145, 149, 153, 157, 161, 165 };
+	static const struct { const unsigned char *ch; unsigned char n, off; }
+		bands[4] = { { b1, 14, 0x08 }, { b3, 12, 0x42 },
+			     { b4, 11, 0x5c }, { b5, 6, 0x74 } };
+	unsigned int link = get16(D.eeprom + 2 * 0x66) << 1, b, i;
+
+	D.n24 = D.n5 = 0;
+	for (b = 0; b < 4; b++) {
+		for (i = 0; i < bands[b].n; i++) {
+			unsigned int off = link + bands[b].off + 2 * i, f, ch;
+			unsigned short e;
+
+			if (off + 2 > EEPROM_SIZE)
+				break;
+			f = D.eeprom[off];
+			ch = bands[b].ch[i];
+			if (!(f & 0x01) || ch == 34 || ch == 38 || ch == 42 ||
+			    ch == 46 || ch == 145)
+				continue;        /* invalid, or not a 20 MHz channel */
+			e = (unsigned short)(ch | (((f & 0x08) && !(f & 0x10)) ? 0x100 : 0));
+			if (b == 0)
+				D.ch24[D.n24++] = e;
+			else if (D.n5 < 32)
+				D.ch5[D.n5++] = e;
+		}
+	}
+	serial_puts(SERIAL_COM1, "iwl: eeprom channels 2.4 ");
+	serial_putdec(SERIAL_COM1, D.n24);
+	serial_puts(SERIAL_COM1, " 5 ");
+	serial_putdec(SERIAL_COM1, D.n5);
+	serial_puts(SERIAL_COM1, "\n");
+}
+
+static int parse_eeprom(void)
+{
+	const unsigned char *m = eeprom_at(2 * 0x15, 0);
+	const unsigned char *x = eeprom_at(2 * 0x128, 1);
+	unsigned int i;
+
+	for (i = 0; i < 6; i++)
+		D.mac[i] = m[i];
+	if ((D.mac[0] & 1) || !(D.mac[0] | D.mac[1] | D.mac[2] | D.mac[3] |
+				 D.mac[4] | D.mac[5])) {
+		logs("EEPROM MAC address invalid");
+		return -1;
+	}
+	D.radio_cfg = get16(eeprom_at(2 * 0x48, 0));
+	D.valid_tx_ant = (D.radio_cfg >> 8) & 0xf;
+	D.valid_rx_ant = (D.radio_cfg >> 12) & 0xf;
+	/* The 6200's iwl_cfg overrides the EEPROM with ANT_BC. */
+	if (iwl_subfamily() == IWL_SUB_6000I)
+		D.valid_tx_ant = D.valid_rx_ant = 0x6;
+	if (!D.valid_tx_ant)
+		D.valid_tx_ant = 0x6;
+	if (!D.valid_rx_ant)
+		D.valid_rx_ant = D.valid_tx_ant;
+	D.first_tx_ant = D.valid_tx_ant & (0u - D.valid_tx_ant);
+	parse_channels();
+	if (x) {
+		D.xtal[0] = x[0];        /* le16 xtal_calib[0], low byte */
+		D.xtal[1] = x[2];
+	}
+	return 0;
+}
+
+/* iwl_nic_config() + iwl6000_nic_config(), run from the transport between
+ * APM init and the ring setup. */
+static void nic_config(void)
+{
+	unsigned int rev = iwl_hw_rev(), v;
+
+	v = iwl_rd(CSR_HW_IF_CONFIG_REG);
+	v = (v & ~0xfu) | (rev & 0xfu);              /* MAC step/dash */
+	v &= ~(0x0c00u | 0xc000u | 0x3000u);
+	v |= ((D.radio_cfg & 3u) << 10) |            /* PHY type */
+	     (((D.radio_cfg >> 2) & 3u) << 14) |     /* PHY step */
+	     (((D.radio_cfg >> 4) & 3u) << 12);      /* PHY dash */
+	v |= 0x0200u | 0x0100u;                      /* RADIO_SI | MAC_SI */
+	iwl_wr(CSR_HW_IF_CONFIG_REG, v);
+	/* NIC stuck after early PCIe power off W/A. */
+	iwl_wr_prph(APMG_PS_CTRL_REG,
+		    iwl_rd_prph(APMG_PS_CTRL_REG) | 0x00400000u);
+	if (iwl_subfamily() == IWL_SUB_6000I)
+		iwl_wr(CSR_GP_DRIVER_REG, 0x00000002u);  /* 2x2 IPA radio SKU */
+}
+
+/* ---- calibration results ------------------------------------------------ */
+static void calib_store(const unsigned char *d, unsigned int n)
+{
+	unsigned int off, rec = (4 + n + 3) & ~3u;
+
+	if (n < 4 || !D.calib)
+		return;
+	/* replace an earlier result with the same op code */
+	for (off = 0; off < D.calib_len;) {
+		unsigned int len = get16(D.calib + off + 2);
+
+		if (D.calib[off] == d[0] && len == n) {
+			iwl_memcpy(D.calib + off + 4, d, n);
+			return;
+		}
+		off += (4 + len + 3) & ~3u;
+	}
+	if (D.calib_len + rec > CALIB_PAGES * 4096) {
+		logs("calibration store full");
+		return;
+	}
+	D.calib[D.calib_len] = d[0];
+	D.calib[D.calib_len + 1] = 0;
+	put16(D.calib + D.calib_len + 2, n);
+	iwl_memcpy(D.calib + D.calib_len + 4, d, n);
+	D.calib_len += rec;
+}
+
+static int calib_send_all(void)
+{
+	unsigned int off, n = 0;
+
+	for (off = 0; off < D.calib_len;) {
+		unsigned int len = get16(D.calib + off + 2);
+
+		if (cmd(REPLY_PHY_CALIBRATION_CMD, D.calib + off + 4, len) < 0)
+			return -1;
+		off += (4 + len + 3) & ~3u;
+		n++;
+	}
+	iwl_loghex("calibration results sent", n);
+	return 0;
+}
+
+static void store_xtal_calib(void)
+{
+	unsigned char c[8] = { IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD, 0, 1, 1,
+			       D.xtal[0], D.xtal[1], 0, 0 };
+
+	calib_store(c, sizeof(c));
+}
+
+/* ---- RX dispatch -------------------------------------------------------- */
+static void rx_phy(const struct iwl_pkt *pkt)
+{
+	const unsigned char *d = pkt->data;
+	unsigned int agc, a, b, c, m;
+
+	if (iwl_pkt_payload_len(pkt) < 60)
+		return;
+	/* struct iwl_rx_phy_res: channel at 18, non_cfg_phy_buf at 20. */
+	D.last_chan = get16(d + 18);
+	agc = (get32(d + 20 + 4) & 0xfe00u) >> 9;
+	a = get32(d + 20 + 8) & 0xff;
+	b = (get32(d + 20 + 8) >> 16) & 0xff;
+	c = get32(d + 20 + 12) & 0xff;
+	m = a > b ? a : b;
+	m = m > c ? m : c;
+	D.last_rssi = (int)m - (int)agc - IWLAGN_RSSI_OFFSET;
+}
+
+static void rx_mpdu(const struct iwl_pkt *pkt)
+{
+	unsigned int plen = iwl_pkt_payload_len(pkt), len, status;
+	const unsigned char *d = pkt->data;
+
+	if (plen < 8)
+		return;
+	len = get16(d);
+	if (4 + len + 4 > plen)
+		return;
+	status = get32(d + 4 + len);
+	if (!(status & IWL_RX_CRC_OK) || !(status & IWL_RX_OVERRUN_OK))
+		return;
+	wifi_rx_frame(d + 4, len, D.last_rssi, status, (unsigned int)D.last_chan);
+}
+
+static int scan_band(int band5);
+
+static void rx_handler(const struct iwl_pkt *pkt)
+{
+	const unsigned char *d = pkt->data;
+	unsigned int n = iwl_pkt_payload_len(pkt);
+
+	switch (pkt->cmd) {
+	case REPLY_ALIVE:
+		if (n >= sizeof(struct alive_resp)) {
+			const struct alive_resp *a = (const void *)d;
+
+			D.alive_ok = a->is_valid == 1;
+			D.err_table = a->error_event_table_ptr;
+			D.alive = 1;
+		}
+		break;
+	case CALIBRATION_RES_NOTIFICATION:
+		calib_store(d, n);
+		break;
+	case CALIBRATION_COMPLETE_NOTIF:
+		D.calib_done = 1;
+		break;
+	case REPLY_RX_PHY_CMD:
+		rx_phy(pkt);
+		break;
+	case REPLY_RX_MPDU_CMD:
+		rx_mpdu(pkt);
+		break;
+	case REPLY_TX:
+		/* struct iwlagn_tx_resp: status at 32.  Unlike the 7265D's
+		 * tx_resp_v3 there is no measurement_req_id/reduced_tpc/
+		 * reserved before tfd_info, so 36 is the agg sequence. */
+		iwl_tx_reclaim((pkt->seq >> 8) & 0x1f, pkt->seq & 0xff);
+		if (n >= 34 && d[32] != 1 && d[32] != 2) {
+			serial_puts(SERIAL_COM1, "iwl: tx failed q");
+			serial_putdec(SERIAL_COM1, (pkt->seq >> 8) & 0x1f);
+			serial_puts(SERIAL_COM1, " status ");
+			serial_puthex(SERIAL_COM1, get16(d + 32));
+			serial_puts(SERIAL_COM1, "\n");
+		}
+		break;
+	case SCAN_COMPLETE_NOTIFICATION:
+		/* DVM scans one band per request: 2.4 GHz, then 5 GHz.  The
+		 * second request is sent from scan_kick(): a synchronous command
+		 * from inside the RX handler would poll the ring re-entrantly. */
+		if (D.scanning && !D.scan_band_5 && D.n5) {
+			D.scan_next5 = 1;
+			break;
+		}
+		D.scanning = 0;
+		wifi_scan_done(1);
+		break;
+	case REPLY_ERROR:
+		if (n >= 8) {
+			serial_puts(SERIAL_COM1, "iwl: REPLY_ERROR type ");
+			serial_puthex(SERIAL_COM1, get32(d));
+			serial_puts(SERIAL_COM1, " cmd ");
+			serial_puthex(SERIAL_COM1, d[4]);
+			serial_puts(SERIAL_COM1, "\n");
+		}
+		break;
+	default:
+		break;
+	}
+}
+
+static void scan_kick(void)
+{
+	if (!D.scan_next5)
+		return;
+	D.scan_next5 = 0;
+	if (scan_band(1) < 0) {
+		D.scanning = 0;
+		wifi_scan_done(0);
+	}
+}
+
+int iwl_dvm_poll(void)
+{
+	int r = iwl_rx_poll();
+
+	scan_kick();
+	return r;
+}
+
+/* ---- firmware load ------------------------------------------------------- */
+/* struct iwl_error_event_table (dvm/main.c): valid, error_id, pc, blink1,
+ * blink2, ilink1, ilink2, data1, data2, line, bcon_time, tsf_low, tsf_hi,
+ * gp1, gp2, gp3.  Dumped once per firmware run, two lines so the netlog
+ * mirror keeps them. */
+static void dump_error_log(void)
+{
+	unsigned int i;
+	static unsigned int dumped_for;
+
+	if (!D.err_table || D.err_table >= 0x01000000u ||
+	    dumped_for == D.err_table + D.alive)
+		return;
+	dumped_for = D.err_table + D.alive;
+	for (i = 0; i < 16; i++) {
+		if (i % 8 == 0)
+			serial_puts(SERIAL_COM1, i ? "\niwl: errlog+8:" : "iwl: errlog:");
+		serial_puts(SERIAL_COM1, " ");
+		serial_puthex(SERIAL_COM1, iwl_mem_rd32(D.err_table + i * 4));
+	}
+	serial_puts(SERIAL_COM1, "\n");
+}
+
+/* iwl_load_ucode_wait_alive() + iwl_alive_notify(). */
+static int load_and_alive(int img)
+{
+	static const unsigned char q_fifo[4] = { 3, 2, 1, 0 }; /* VO VI BE BK */
+	unsigned char coex[4 + 16 * 4];
+	unsigned int t, i;
+
+	D.alive = 0;
+	if (iwl_start_hw() < 0 || iwl_load_fw(img) < 0)
+		return -1;
+	for (t = 0; t < 1000 && !D.alive; t++) {
+		if (iwl_rx_poll() < 0)
+			break;
+		if (!D.alive)
+			iwl_udelay(1000);
+	}
+	if (!D.alive || !D.alive_ok) {
+		logs(D.alive ? "loaded ucode is not valid" : "no ALIVE from firmware");
+		return -1;
+	}
+	iwl_udelay(5000);                     /* give RF-kill time to run */
+	iwl_fw_alive(0);
+	for (i = 0; i < 4; i++)
+		iwl_txq_enable_fifo(i, q_fifo[i]);
+	iwl_memzero(coex, sizeof(coex));      /* WiMAX coexistence off */
+	if (cmd(COEX_PRIORITY_TABLE_CMD, coex, sizeof(coex)) < 0)
+		return -1;
+	store_xtal_calib();
+	return calib_send_all();
+}
+
+static int run_init_image(void)
+{
+	struct calib_cfg_cmd c;
+	unsigned int t;
+
+	D.state = "init image";
+	D.calib_done = 0;
+	if (load_and_alive(IWL_IMG_INIT) < 0)
+		return -1;
+	iwl_memzero(&c, sizeof(c));
+	c.ucd_once.is_enable = IWL_CALIB_INIT_CFG_ALL;
+	c.ucd_once.start = IWL_CALIB_INIT_CFG_ALL;
+	c.ucd_once.send_res = IWL_CALIB_INIT_CFG_ALL;
+	c.ucd_flags = IWL_CALIB_SEND_COMPLETE;
+	if (cmd(CALIBRATION_CFG_CMD, &c, sizeof(c)) < 0)
+		return -1;
+	for (t = 0; t < 2000 && !D.calib_done; t++) {
+		if (iwl_rx_poll() < 0)
+			break;
+		if (!D.calib_done)
+			iwl_udelay(1000);
+	}
+	iwl_stop_device();
+	if (!D.calib_done) {
+		logs("INIT calibration did not complete");
+		dump_error_log();
+		return -1;
+	}
+	return 0;
+}
+
+/* ---- stations ------------------------------------------------------------ */
+static int send_add_sta(const struct addsta_cmd *c)
+{
+	unsigned char r[4] = { 0, 0, 0, 0 };
+
+	if (iwl_send_cmd(REPLY_ADD_STA, c, sizeof(*c), r, 4) < 0)
+		return -1;
+	if (!(r[0] & 1)) {                    /* ADD_STA_SUCCESS_MSK */
+		iwl_loghex("ADD_STA failed, status", r[0]);
+		return -1;
+	}
+	return 0;
+}
+
+static int send_lq(unsigned int sta, unsigned int rate)
+{
+	struct lq_cmd q;
+	unsigned int i;
+
+	iwl_memzero(&q, sizeof(q));
+	q.sta_id = sta;
+	q.single_ant = D.first_tx_ant;
+	q.dual_ant = D.valid_tx_ant & ~D.first_tx_ant;
+	if (!q.dual_ant)
+		q.dual_ant = 0x3;
+	q.agg_dis_start_th = 3;
+	q.agg_time_limit = 4000;
+	for (i = 0; i < 16; i++)
+		q.rs_table[i] = rate;
+	return cmd(REPLY_TX_LINK_QUALITY_CMD, &q, sizeof(q));
+}
+
+static unsigned int mgmt_rate(void)
+{
+	return D.chan > 14 ? (PLCP_6M | (D.first_tx_ant << RATE_ANT_POS))
+			   : (PLCP_1M | RATE_CCK | (D.first_tx_ant << RATE_ANT_POS));
+}
+
+static int add_station(unsigned int id, const unsigned char addr[6])
+{
+	struct addsta_cmd c;
+
+	iwl_memzero(&c, sizeof(c));
+	c.mode = 0;
+	iwl_memcpy(c.addr, addr, 6);
+	c.sta_id = id;
+	c.key.key_flags = STA_KEY_FLG_INVALID;
+	c.key.key_offset = 0xff;
+	if (send_add_sta(&c) < 0)
+		return -1;
+	return send_lq(id, mgmt_rate());
+}
+
+/* Un-assoc RXON clears the station table: re-add what we know. */
+static int restore_stations(void)
+{
+	static const unsigned char bcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+
+	if (add_station(IWLAGN_BROADCAST_ID, bcast) < 0)
+		return -1;
+	if (D.ap_sta && add_station(IWL_AP_ID, D.bssid) < 0)
+		return -1;
+	return 0;
+}
+
+/* ---- RXON ---------------------------------------------------------------- */
+static void rxon_defaults(void)
+{
+	struct rxon_cmd *r = &D.rxon;
+	unsigned int rx = D.valid_rx_ant;
+	unsigned int cnt = (rx & (rx - 1)) ? 2 : 1;
+
+	iwl_memzero(r, sizeof(*r));
+	iwl_memcpy(r->node_addr, D.mac, 6);
+	r->dev_type = RXON_DEV_TYPE_ESS;
+	r->filter_flags = RXON_FILTER_ACCEPT_GRP;
+	/* iwlagn_set_rxon_chain(): valid chains, single-stream counts. */
+	r->rx_chain = (unsigned short)((rx << 1) | (cnt << 10) | (cnt << 12));
+	r->ht_single = r->ht_dual = r->ht_triple = 0xff;
+	r->channel = 1;
+	r->flags = RXON_FLG_BAND_24G | RXON_FLG_AUTO_DETECT;
+}
+
+static void rxon_set_channel(unsigned int chan)
+{
+	struct rxon_cmd *r = &D.rxon;
+
+	r->channel = chan;
+	if (chan > 14)
+		r->flags = (r->flags & ~(RXON_FLG_BAND_24G | RXON_FLG_AUTO_DETECT)) |
+			   RXON_FLG_SHORT_SLOT;
+	else
+		r->flags = (r->flags & ~RXON_FLG_SHORT_SLOT) |
+			   RXON_FLG_BAND_24G | RXON_FLG_AUTO_DETECT;
+	D.chan = chan;
+}
+
+static int send_tx_power(void)
+{
+	/* iwlagn_tx_power_dbm_cmd: 15 dBm global limit in half-dBm,
+	 * IWLAGN_TX_POWER_NO_CLOSED, srv_chan_lmt IWLAGN_TX_POWER_AUTO. */
+	unsigned char c[4] = { 30, 0x40, 0x7f, 0 };
+
+	return cmd(REPLY_TX_POWER_DBM_CMD, c, sizeof(c));
+}
+
+static int send_qos(void)
+{
+	unsigned char c[4 + 4 * 8];
+	unsigned int i;
+
+	iwl_memzero(c, sizeof(c));
+	for (i = 0; i < 4; i++) {            /* non-QoS EDCA: 15/1023, AIFS 2 */
+		put16(c + 4 + i * 8, 15);
+		put16(c + 4 + i * 8 + 2, 1023);
+		c[4 + i * 8 + 4] = 2;
+	}
+	return cmd(REPLY_QOS_PARAM, c, sizeof(c));
+}
+
+static int send_timing(unsigned int bi, unsigned int dtim)
+{
+	struct rxon_timing t;
+
+	iwl_memzero(&t, sizeof(t));
+	t.beacon_interval = bi ? bi : 100;
+	t.listen_interval = 10;
+	t.beacon_init_val = (unsigned int)t.beacon_interval * 1024u;
+	t.dtim_period = dtim ? dtim : 1;
+	return cmd(REPLY_RXON_TIMING, &t, sizeof(t));
+}
+
+/* iwlagn_commit_rxon(): always clear the association first (which wipes
+ * the station table), restore the stations, then connect if asked. */
+static int commit_rxon(int assoc, unsigned short aid, unsigned int bi,
+		       unsigned int dtim)
+{
+	struct rxon_cmd *r = &D.rxon;
+
+	r->flags |= RXON_FLG_TSF2HOST;
+	r->cck_basic_rates = r->channel <= 14 ? 0x0f : 0;
+	r->ofdm_basic_rates = 0x15;          /* 6, 12, 24 Mb/s */
+	r->filter_flags &= ~RXON_FILTER_ASSOC;
+	r->assoc_id = 0;
+	if (cmd(REPLY_RXON, r, sizeof(*r)) < 0)
+		return -1;
+	if (restore_stations() < 0)
+		return -1;
+	if (assoc) {
+		if (send_timing(bi, dtim) < 0 || send_qos() < 0)
+			return -1;
+		r->filter_flags |= RXON_FILTER_ASSOC;
+		r->assoc_id = aid;
+		if (cmd(REPLY_RXON, r, sizeof(*r)) < 0)
+			return -1;
+	}
+	D.assoc = assoc;
+	/* A tune needs a new TX power command, or nothing can be sent. */
+	return send_tx_power();
+}
+
+/* ---- bring-up ------------------------------------------------------------ */
+static int run_rt_image(void)
+{
+	struct calib_cfg_cmd c;
+	unsigned int ant = D.valid_tx_ant;
+	unsigned char power[36];
+
+	D.state = "runtime image";
+	if (load_and_alive(IWL_IMG_RT) < 0)
+		return -1;
+	/* iwlagn_send_calib_cfg_rt(DC) */
+	iwl_memzero(&c, sizeof(c));
+	c.ucd_once.is_enable = IWL_CALIB_RT_CFG_ALL;
+	c.ucd_once.start = IWL_CALIB_CFG_DC;
+	if (cmd(CALIBRATION_CFG_CMD, &c, sizeof(c)) < 0)
+		return -1;
+	if (cmd(TX_ANT_CONFIGURATION_CMD, &ant, 4) < 0)
+		return -1;
+	rxon_defaults();
+	D.ap_sta = 0;
+	if (commit_rxon(0, 0, 0, 0) < 0)
+		return -1;
+	iwl_memzero(power, sizeof(power));   /* CAM: no power save */
+	return cmd(POWER_TABLE_CMD, power, sizeof(power));
+}
+
+int iwl_dvm_up(unsigned char mac[6])
+{
+	if (D.up) {
+		iwl_memcpy(mac, D.mac, 6);
+		return 0;
+	}
+	if (iwl_probe() < 0 || !iwl_is_dvm()) {
+		D.state = "no card";
+		return -1;
+	}
+	if (iwl_fw_parse() < 0) {
+		D.state = "firmware missing";
+		return -1;
+	}
+	if (!D.calib) {
+		D.calib = (unsigned char *)mm_alloc_pages(CALIB_PAGES);
+		D.eeprom = (unsigned char *)mm_alloc_page();
+		D.scratch = (unsigned char *)mm_alloc_pages(2);
+		if (!D.calib || !D.eeprom || !D.scratch) {
+			D.calib = 0;
+			D.state = "out of memory";
+			return -1;
+		}
+	}
+	D.state = "eeprom";
+	if (iwl_start_hw() < 0 || read_eeprom() < 0 || parse_eeprom() < 0) {
+		iwl_stop_device();
+		if (D.state[0] == 'e')
+			D.state = "EEPROM read failed";
+		return -1;
+	}
+	serial_puts(SERIAL_COM1, "iwl: radio cfg ");
+	serial_puthex(SERIAL_COM1, D.radio_cfg);
+	serial_puts(SERIAL_COM1, " tx ant ");
+	serial_puthex(SERIAL_COM1, D.valid_tx_ant);
+	serial_puts(SERIAL_COM1, "\n");
+	if (iwl_rfkill()) {
+		logs("radio is off (hardware RF-kill switch)");
+		iwl_stop_device();
+		D.state = "RF-kill switch is on";
+		return -1;
+	}
+	iwl_set_nic_config(nic_config);
+	iwl_set_rx_handler(rx_handler);
+	D.calib_len = 0;
+	if (run_init_image() < 0 || run_rt_image() < 0) {
+		dump_error_log();
+		iwl_stop_device();
+		D.state = "firmware start failed";
+		return -1;
+	}
+	D.up = 1;
+	D.state = "ready";
+	iwl_memcpy(mac, D.mac, 6);
+	logs("firmware running");
+	return 0;
+}
+
+int iwl_dvm_is_up(void)
+{
+	return D.up;
+}
+
+const char *iwl_dvm_state(void)
+{
+	return D.state ? D.state : "down";
+}
+
+void iwl_dvm_down(void)
+{
+	if (iwl_present())
+		iwl_stop_device();
+	D.up = 0;
+	D.scanning = 0;
+	D.ap_sta = D.assoc = 0;
+	D.have_tk = 0;
+	D.state = "down";
+}
+
+/* ---- scan ---------------------------------------------------------------- */
+static int scan_band(int band5)
+{
+	struct scan_cmd *s = (struct scan_cmd *)D.scratch;
+	const unsigned short *list = band5 ? D.ch5 : D.ch24;
+	unsigned int n = band5 ? D.n5 : D.n24, i, o;
+	unsigned char *f;
+	struct scan_chan *ch;
+	static const unsigned char r24[] = { 1, 8, 0x82, 0x84, 0x8b, 0x96,
+					     0x0c, 0x12, 0x18, 0x24,
+					     50, 4, 0x30, 0x48, 0x60, 0x6c };
+	static const unsigned char r5[] = { 1, 8, 0x8c, 0x12, 0x98, 0x24,
+					    0xb0, 0x48, 0x60, 0x6c };
+	unsigned int rx = D.valid_rx_ant;
+
+	iwl_memzero(D.scratch, 4096);
+	s->quiet_plcp_th = 1;                    /* IWL_PLCP_QUIET_THRESH */
+	s->quiet_time = 10;                      /* IWL_ACTIVE_QUIET_TIME */
+	s->good_crc_th = 1;                      /* IWL_GOOD_CRC_TH_DEFAULT */
+	s->rx_chain = (unsigned short)((rx << 1) | (rx << 7) | (rx << 4) | 1);
+	s->flags = band5 ? 0 : (RXON_FLG_BAND_24G | RXON_FLG_AUTO_DETECT);
+	s->filter_flags = RXON_FILTER_ACCEPT_GRP | (1u << 6); /* BCON_AWARE */
+	s->tx.tx_flags = TX_FLG_SEQ_CTL;
+	s->tx.sta_id = IWLAGN_BROADCAST_ID;
+	s->tx.life_time = 0xffffffffu;
+	s->tx.rate_n_flags = (band5 ? PLCP_6M : (PLCP_1M | RATE_CCK)) |
+			     (D.first_tx_ant << RATE_ANT_POS);
+	/* Probe request: broadcast, wildcard SSID, our rates. */
+	f = D.scratch + sizeof(*s);
+	f[0] = 0x40;
+	for (i = 0; i < 6; i++) {
+		f[4 + i] = 0xff;
+		f[10 + i] = D.mac[i];
+		f[16 + i] = 0xff;
+	}
+	o = 24;
+	f[o++] = 0;
+	f[o++] = 0;
+	if (band5) {
+		iwl_memcpy(f + o, r5, sizeof(r5));
+		o += sizeof(r5);
+	} else {
+		iwl_memcpy(f + o, r24, sizeof(r24));
+		o += sizeof(r24);
+	}
+	s->tx.len = o;
+	ch = (struct scan_chan *)(f + o);
+	for (i = 0; i < n; i++) {
+		ch[i].channel = list[i] & 0xff;
+		ch[i].type = (list[i] & 0x100) ? 1 : 0;   /* active : passive */
+		ch[i].active_dwell = band5 ? 22 : 33;
+		ch[i].passive_dwell = band5 ? 110 : 120;
+		ch[i].dsp_atten = 110;
+		ch[i].tx_gain = band5 ? ((1 << 5) | (3 << 3) | 3) : ((1 << 5) | (5 << 3));
+	}
+	s->channel_count = n;
+	s->len = (unsigned short)(sizeof(*s) + o + n * sizeof(struct scan_chan));
+	D.scan_band_5 = band5;
+	serial_puts(SERIAL_COM1, "iwl: scan band ");
+	serial_puts(SERIAL_COM1, band5 ? "5" : "2.4");
+	serial_puts(SERIAL_COM1, " len ");
+	serial_putdec(SERIAL_COM1, s->len);
+	serial_puts(SERIAL_COM1, " chans ");
+	serial_putdec(SERIAL_COM1, n);
+	serial_puts(SERIAL_COM1, "\n");
+	return cmd(REPLY_SCAN_CMD, s, s->len);
+}
+
+int iwl_dvm_scan_running(void)
+{
+	scan_kick();
+	return D.scanning;
+}
+
+int iwl_dvm_scan_start(void)
+{
+	if (!D.up || D.scanning || D.assoc || !D.n24)
+		return -1;
+	D.scanning = 1;
+	D.scan_next5 = 0;
+	if (scan_band(0) < 0) {
+		D.scanning = 0;
+		return -1;
+	}
+	return 0;
+}
+
+/* ---- connection ---------------------------------------------------------- */
+int iwl_dvm_prepare_connect(const unsigned char bssid[6], unsigned int chan,
+			    unsigned int beacon_int)
+{
+	(void)beacon_int;
+	if (!D.up)
+		return -1;
+	if (D.ap_sta || D.assoc)
+		iwl_dvm_disconnect();
+	iwl_memcpy(D.bssid, bssid, 6);
+	iwl_memcpy(D.rxon.bssid_addr, bssid, 6);
+	rxon_set_channel(chan);
+	D.ap_sta = 1;            /* restore_stations() adds the AP station */
+	D.have_tk = 0;
+	if (commit_rxon(0, 0, 0, 0) < 0) {
+		D.ap_sta = 0;
+		return -1;
+	}
+	return 0;
+}
+
+int iwl_dvm_set_assoc(unsigned short aid, unsigned int beacon_int,
+		      unsigned int dtim)
+{
+	if (!D.ap_sta)
+		return -1;
+	if (commit_rxon(1, aid, beacon_int, dtim) < 0)
+		return -1;
+	/* Data at a fixed OFDM rate on the first antenna. */
+	return send_lq(IWL_AP_ID, PLCP_12M | (D.first_tx_ant << RATE_ANT_POS));
+}
+
+void iwl_dvm_disconnect(void)
+{
+	unsigned int i;
+
+	if (!D.up)
+		return;
+	D.ap_sta = 0;
+	D.have_tk = 0;
+	for (i = 0; i < 6; i++)
+		D.rxon.bssid_addr[i] = 0;
+	commit_rxon(0, 0, 0, 0);
+}
+
+/* ---- TX ------------------------------------------------------------------ */
+static int tx_frame(const unsigned char *frame, unsigned int len, int mgmt,
+		    int protect)
+{
+	struct tx_cmd c;
+	int bcast = frame[4] & 1;
+	unsigned int stype = (frame[0] >> 4) & 0xf;
+	unsigned int sta = D.ap_sta ? IWL_AP_ID : IWLAGN_BROADCAST_ID;
+	int q = mgmt ? IWL_DVM_Q_VO : IWL_DVM_Q_BE;
+
+	iwl_memzero(&c, sizeof(c));
+	c.len = len;
+	c.tx_flags = TX_FLG_SEQ_CTL | (bcast ? 0 : TX_FLG_ACK);
+	c.rate_n_flags = mgmt ? mgmt_rate()
+			      : (PLCP_12M | (D.first_tx_ant << RATE_ANT_POS));
+	c.tid_tspec = 8;                     /* IWL_TID_NON_QOS (= 8 on DVM) */
+	c.pm_frame_timeout = mgmt ? ((stype == 0 || stype == 2) ? 3 : 2) : 0;
+	c.sta_id = sta;
+	c.life_time = 0xffffffffu;
+	c.rts_retry_limit = 60;
+	c.data_retry_limit = mgmt ? 3 : 15;
+	if (protect) {
+		if (!D.have_tk)
+			return -1;
+		c.sec_ctl = TX_SEC_CCM;
+		iwl_memcpy(c.key, D.tk, 16);
+	}
+	return iwl_tx(q, &c, sizeof(c), frame, len, sta, protect ? 8 : 0);
+}
+
+int iwl_dvm_tx_mgmt(const unsigned char *frame, unsigned int len)
+{
+	return D.up ? tx_frame(frame, len, 1, 0) : -1;
+}
+
+int iwl_dvm_tx_data(const unsigned char *frame, unsigned int len, int protect)
+{
+	return D.up && D.ap_sta ? tx_frame(frame, len, 0, protect) : -1;
+}
+
+/* ---- keys ---------------------------------------------------------------- */
+int iwl_dvm_set_key(int pairwise, int keyidx, const unsigned char key[16],
+		    const unsigned char rsc[6])
+{
+	struct addsta_cmd c;
+
+	(void)rsc;          /* RX replay counters start at 0 (see iwl_mvm.c) */
+	if (!D.ap_sta)
+		return -1;
+	/* iwlagn_send_sta_key(): ADD_STA modify on the AP station; the group
+	 * key also lives on the AP station in station mode. */
+	iwl_memzero(&c, sizeof(c));
+	c.mode = STA_CONTROL_MODIFY;
+	iwl_memcpy(c.addr, D.bssid, 6);
+	c.sta_id = IWL_AP_ID;
+	c.modify_mask = STA_MODIFY_KEY_MASK;
+	c.key.key_flags = (unsigned short)(((keyidx & 3) << 8) |
+					   STA_KEY_FLG_MAP_KEY | STA_KEY_FLG_CCMP);
+	if (!pairwise)
+		c.key.key_flags |= STA_KEY_MULTICAST;
+	c.key.key_offset = pairwise ? 0 : 1;
+	iwl_memcpy(c.key.key, key, 16);
+	if (send_add_sta(&c) < 0)
+		return -1;
+	if (pairwise) {
+		iwl_memcpy(D.tk, key, 16);
+		D.have_tk = 1;
+	}
+	return 0;
+}
+
+void iwl_dvm_clear_keys(void)
+{
+	D.have_tk = 0;
+}

+ 30 - 0
iwl_dvm.h

@@ -0,0 +1,30 @@
+/* Intel 6200/6300 (iwlwifi "6000" family) firmware layer ("dvm"): see
+ * iwl_dvm.c.  Same entry points as iwl_mvm.h; iwl_fw.c picks one of the two
+ * by the probed device family.
+ *
+ * One BSS RXON context: the AP station is ID 0 (IWL_AP_ID), the broadcast
+ * station ID 15 (IWLAGN_BROADCAST_ID); management frames go on the VO
+ * queue, non-QoS data on BE. */
+#ifndef IWL_DVM_H
+#define IWL_DVM_H
+
+int  iwl_dvm_up(unsigned char mac[6]);
+int  iwl_dvm_is_up(void);
+void iwl_dvm_down(void);
+const char *iwl_dvm_state(void);
+int  iwl_dvm_poll(void);
+int  iwl_dvm_scan_start(void);
+int  iwl_dvm_scan_running(void);
+int  iwl_dvm_prepare_connect(const unsigned char bssid[6], unsigned int chan,
+			     unsigned int beacon_int);
+int  iwl_dvm_set_assoc(unsigned short aid, unsigned int beacon_int,
+		       unsigned int dtim);
+void iwl_dvm_disconnect(void);
+int  iwl_dvm_tx_mgmt(const unsigned char *frame, unsigned int len);
+int  iwl_dvm_tx_data(const unsigned char *frame, unsigned int len,
+		     int protect);
+int  iwl_dvm_set_key(int pairwise, int keyidx, const unsigned char key[16],
+		     const unsigned char rsc[6]);
+void iwl_dvm_clear_keys(void);
+
+#endif

+ 90 - 0
iwl_fw.c

@@ -0,0 +1,90 @@
+/* Firmware-layer dispatch: see iwl_fw.h. */
+
+#include "iwl_fw.h"
+#include "iwl_dvm.h"
+#include "iwl_mvm.h"
+#include "iwl_trans.h"
+
+int iwlfw_up(unsigned char mac[6])
+{
+	if (iwl_probe() == 0 && iwl_is_dvm())
+		return iwl_dvm_up(mac);
+	return iwl_mvm_up(mac);
+}
+
+void iwlfw_down(void)
+{
+	if (iwl_is_dvm())
+		iwl_dvm_down();
+	else
+		iwl_mvm_down();
+}
+
+const char *iwlfw_state(void)
+{
+	return iwl_is_dvm() ? iwl_dvm_state() : iwl_mvm_state();
+}
+
+int iwlfw_poll(void)
+{
+	return iwl_is_dvm() ? iwl_dvm_poll() : iwl_mvm_poll();
+}
+
+int iwlfw_scan_start(void)
+{
+	return iwl_is_dvm() ? iwl_dvm_scan_start() : iwl_mvm_scan_start();
+}
+
+int iwlfw_scan_running(void)
+{
+	return iwl_is_dvm() ? iwl_dvm_scan_running() : iwl_mvm_scan_running();
+}
+
+int iwlfw_prepare_connect(const unsigned char bssid[6], unsigned int chan,
+			  unsigned int beacon_int)
+{
+	return iwl_is_dvm() ? iwl_dvm_prepare_connect(bssid, chan, beacon_int)
+			    : iwl_mvm_prepare_connect(bssid, chan, beacon_int);
+}
+
+int iwlfw_set_assoc(unsigned short aid, unsigned int beacon_int,
+		    unsigned int dtim)
+{
+	return iwl_is_dvm() ? iwl_dvm_set_assoc(aid, beacon_int, dtim)
+			    : iwl_mvm_set_assoc(aid, beacon_int, dtim);
+}
+
+void iwlfw_disconnect(void)
+{
+	if (iwl_is_dvm())
+		iwl_dvm_disconnect();
+	else
+		iwl_mvm_disconnect();
+}
+
+int iwlfw_tx_mgmt(const unsigned char *frame, unsigned int len)
+{
+	return iwl_is_dvm() ? iwl_dvm_tx_mgmt(frame, len)
+			    : iwl_mvm_tx_mgmt(frame, len);
+}
+
+int iwlfw_tx_data(const unsigned char *frame, unsigned int len, int protect)
+{
+	return iwl_is_dvm() ? iwl_dvm_tx_data(frame, len, protect)
+			    : iwl_mvm_tx_data(frame, len, protect);
+}
+
+int iwlfw_set_key(int pairwise, int keyidx, const unsigned char key[16],
+		  const unsigned char rsc[6])
+{
+	return iwl_is_dvm() ? iwl_dvm_set_key(pairwise, keyidx, key, rsc)
+			    : iwl_mvm_set_key(pairwise, keyidx, key, rsc);
+}
+
+void iwlfw_clear_keys(void)
+{
+	if (iwl_is_dvm())
+		iwl_dvm_clear_keys();
+	else
+		iwl_mvm_clear_keys();
+}

+ 24 - 0
iwl_fw.h

@@ -0,0 +1,24 @@
+/* Firmware-layer dispatch for wifi.c: the 7000 family (7265D/3165) runs
+ * iwl_mvm.c, the 6000 family (6200/6300) iwl_dvm.c.  The family comes from
+ * the PCI probe (iwl_is_dvm()); every call has the iwl_mvm.h semantics. */
+#ifndef IWL_FW_H
+#define IWL_FW_H
+
+int  iwlfw_up(unsigned char mac[6]);
+void iwlfw_down(void);
+const char *iwlfw_state(void);
+int  iwlfw_poll(void);
+int  iwlfw_scan_start(void);
+int  iwlfw_scan_running(void);
+int  iwlfw_prepare_connect(const unsigned char bssid[6], unsigned int chan,
+			   unsigned int beacon_int);
+int  iwlfw_set_assoc(unsigned short aid, unsigned int beacon_int,
+		     unsigned int dtim);
+void iwlfw_disconnect(void);
+int  iwlfw_tx_mgmt(const unsigned char *frame, unsigned int len);
+int  iwlfw_tx_data(const unsigned char *frame, unsigned int len, int protect);
+int  iwlfw_set_key(int pairwise, int keyidx, const unsigned char key[16],
+		   const unsigned char rsc[6]);
+void iwlfw_clear_keys(void);
+
+#endif

+ 250 - 46
iwl_trans.c

@@ -18,7 +18,37 @@
 #include "ramfs.h"
 #include "serial.h"
 
-#define FW_PATH "firmware/iwlwifi-7265D-29.ucode"
+/* Per-family transport parameters (Linux: iwl_cfg_trans_params plus the
+ * op_mode's iwl_trans_config).  The 7000 family runs the MVM firmware with
+ * DQA queues and wide command headers; the 6000 family runs the DVM
+ * firmware with the four AC queues, the command queue on 4 and 4-byte
+ * headers. */
+struct iwl_family {
+	const char *fw_path;
+	unsigned char dvm;            /* DVM firmware (6000) vs MVM (7000) */
+	unsigned char tlv;            /* TLV .ucode vs the v2 fixed header */
+	unsigned char cmd_q, cmd_fifo, nq;
+	unsigned char wide_hdr;       /* mvm: trans->wide_cmd_header */
+	unsigned char bc_dword;       /* byte-count table in dwords */
+	unsigned char scd_set_active; /* mvm: trans_cfg.scd_set_active */
+	unsigned char chain_ext_wa;   /* base_params->scd_chain_ext_wa */
+	unsigned char shadow_reg;     /* base_params->shadow_reg_enable */
+	unsigned char wake_me;        /* tell ME we leave (7000 family) */
+	unsigned char q[4], q_slots[4]; /* data/mgmt queues to allocate */
+};
+
+static const struct iwl_family fam_7000 = {
+	"firmware/iwlwifi-7265D-29.ucode", 0, 1, IWL_Q_CMD, 7, 31,
+	1, 1, 1, 0, 1, 1,
+	{ IWL_Q_AUX, IWL_Q_BSS, 0xff, 0xff }, { 8, 32, 0, 0 },
+};
+
+static const struct iwl_family fam_6000 = {
+	"firmware/iwlwifi-6000-4.ucode", 1, 0, IWL_DVM_Q_CMD, 7, 20,
+	0, 0, 0, 1, 0, 0,
+	{ IWL_DVM_Q_VO, IWL_DVM_Q_VI, IWL_DVM_Q_BE, IWL_DVM_Q_BK },
+	{ 16, 4, 32, 4 },
+};
 
 /* ---- CSR / HBUS / FH / PRPH registers (iwl-csr.h, iwl-fh.h, iwl-prph.h) */
 #define CSR_HW_IF_CONFIG_REG     0x000
@@ -109,6 +139,7 @@
 #define SCD_DRAM_BASE_ADDR       (SCD_BASE + 0x8)
 #define SCD_TXFACT               (SCD_BASE + 0x10)
 #define SCD_QUEUECHAIN_SEL       (SCD_BASE + 0xe8)
+#define SCD_CHAINEXT_EN          (SCD_BASE + 0x244)
 #define SCD_AGGR_SEL             (SCD_BASE + 0x248)
 #define SCD_GP_CTRL              (SCD_BASE + 0x1a8)
 #define SCD_EN_CTRL              (SCD_BASE + 0x254)
@@ -186,6 +217,12 @@ struct iwl_state {
 	struct iwl_fw_info fw;
 	const unsigned char *fw_data;
 	unsigned int fw_size;
+	const struct iwl_family *fam;
+	unsigned int sub;           /* IWL_SUB_* within the family */
+	void (*nic_config)(void);   /* op-mode NIC config (DVM), may be 0 */
+	/* v2 (pre-TLV) image: [IWL_IMG_*] instruction and data sections */
+	const unsigned char *img_inst[2], *img_data[2];
+	unsigned int img_inst_len[2], img_data_len[2];
 };
 
 static struct iwl_state *S;   /* page-allocated on probe */
@@ -317,15 +354,49 @@ static int grab_nic(void)
 }
 
 /* ---- probe --------------------------------------------------------------- */
-static const char *chip_for(unsigned int devid)
+static const char *chip_for(unsigned int devid,
+			    const struct iwl_family **fam, unsigned int *sub)
 {
+	*fam = &fam_7000;
+	*sub = IWL_SUB_7265;
 	switch (devid) {
 	case 0x095a: case 0x095b: return "Intel Wireless 7265";
 	case 0x3165: case 0x3166: return "Intel Wireless 3165";
 	}
+	*fam = &fam_6000;
+	switch (devid) {
+	case 0x4239: case 0x422c:
+		*sub = IWL_SUB_6000I;
+		return "Intel Centrino Advanced-N 6200";
+	case 0x4238: case 0x422b:
+		*sub = IWL_SUB_6000;
+		return "Intel Centrino Ultimate-N 6300";
+	}
 	return 0;
 }
 
+/* The firmware reported SW_ERR/HW_ERR: it is dead until reloaded. */
+int iwl_fatal(void)
+{
+	return S && S->fatal;
+}
+
+int iwl_is_dvm(void)
+{
+	return S && S->fam->dvm;
+}
+
+unsigned int iwl_subfamily(void)
+{
+	return S ? S->sub : 0;
+}
+
+void iwl_set_nic_config(void (*fn)(void))
+{
+	if (S)
+		S->nic_config = fn;
+}
+
 int iwl_present(void)
 {
 	return S != 0;
@@ -397,12 +468,13 @@ int iwl_probe(void)
 			nfunc = (pci_cfg_read32(bus, dev, 0, 0x0c) & 0x800000u) ? 8 : 1;
 			for (func = 0; func < nfunc; func++) {
 				unsigned int idf = pci_cfg_read32(bus, dev, func, 0);
-				unsigned int bar, cmd, page;
+				unsigned int bar, cmd, page, sub;
+				const struct iwl_family *fam;
 				const char *name;
 
 				if ((idf & 0xffffu) != 0x8086)
 					continue;
-				name = chip_for(idf >> 16);
+				name = chip_for(idf >> 16, &fam, &sub);
 				if (!name)
 					continue;
 				bar = pci_cfg_read32(bus, dev, func, 0x10);
@@ -424,6 +496,8 @@ int iwl_probe(void)
 				S->func = func;
 				S->devid = idf >> 16;
 				S->chip = name;
+				S->fam = fam;
+				S->sub = sub;
 				pci_d0(bus, dev, func);
 				/* Memory + bus master, INTx off (polled). */
 				cmd = pci_cfg_read32(bus, dev, func, 0x04);
@@ -453,7 +527,8 @@ int iwl_probe(void)
 				}
 				/* 0x095a/b: only rev-D silicon runs the 7265D
 				 * firmware (Linux: CSR_HW_REV_TYPE_7265D). */
-				if (S->devid != 0x3165 && S->devid != 0x3166 &&
+				if (!fam->dvm &&
+				    S->devid != 0x3165 && S->devid != 0x3166 &&
 				    (S->hw_rev & 0xfff0u) != 0x210u)
 					iwl_log("warning: not a 7265D; the 7265D firmware may fail");
 				return 0;
@@ -478,6 +553,57 @@ static unsigned int le32(const unsigned char *p)
 	return p[0] | (p[1] << 8) | (p[2] << 16) | ((unsigned int)p[3] << 24);
 }
 
+/* Pre-TLV image (iwl-drv.c iwl_parse_v1_v2_firmware(), API >= 3 = v2):
+ * ver, build, inst, data, init, init_data, boot sizes, then the sections
+ * in that order. */
+static int fw_parse_v2(const unsigned char *d, unsigned int size)
+{
+	unsigned int inst, data, init, initd, boot, o = 28;
+
+	if (size < 28)
+		return -1;
+	S->fw.ver = le32(d);
+	inst = le32(d + 8);
+	data = le32(d + 12);
+	init = le32(d + 16);
+	initd = le32(d + 20);
+	boot = le32(d + 24);
+	if (((S->fw.ver >> 8) & 0xff) < 3 ||
+	    o + inst + data + init + initd + boot != size || !inst || !init) {
+		iwl_log("firmware is not a v2 .ucode image");
+		return -1;
+	}
+	S->img_inst[IWL_IMG_RT] = d + o;
+	S->img_inst_len[IWL_IMG_RT] = inst;
+	o += inst;
+	S->img_data[IWL_IMG_RT] = d + o;
+	S->img_data_len[IWL_IMG_RT] = data;
+	o += data;
+	S->img_inst[IWL_IMG_INIT] = d + o;
+	S->img_inst_len[IWL_IMG_INIT] = init;
+	o += init;
+	S->img_data[IWL_IMG_INIT] = d + o;
+	S->img_data_len[IWL_IMG_INIT] = initd;
+	{
+		static const char hx[] = "0123456789abcdef";
+		unsigned int i, v = S->fw.ver;
+		char *h = S->fw.human;
+
+		/* "6000 v9.221.4.1", like Linux's "%u.%u.%u.%u" */
+		h[0] = 'v';
+		for (i = 0; i < 4; i++) {
+			unsigned int b = (v >> (24 - 8 * i)) & 0xff;
+
+			*++h = hx[b >> 4 & 0xf];
+			*++h = hx[b & 0xf];
+			if (i < 3)
+				*++h = '.';
+		}
+		*++h = 0;
+	}
+	return 0;
+}
+
 int iwl_fw_parse(void)
 {
 	const unsigned char *d;
@@ -487,9 +613,23 @@ int iwl_fw_parse(void)
 		return -1;
 	if (S->fw.present)
 		return 0;
-	d = ramfs_lookup(FW_PATH, &size);
-	if (!d || size < 88 || le32(d) != 0 || le32(d + 4) != 0x0a4c5749u) {
-		iwl_log("firmware " FW_PATH " missing or not a TLV image");
+	d = ramfs_lookup(S->fam->fw_path, &size);
+	if (!d) {
+		iwl_log("firmware missing from /ramfs:");
+		iwl_log(S->fam->fw_path);
+		return -1;
+	}
+	if (!S->fam->tlv) {
+		if (fw_parse_v2(d, size) < 0)
+			return -1;
+		S->fw_data = d;
+		S->fw_size = size;
+		S->fw.present = 1;
+		iwl_log(S->fw.human);
+		return 0;
+	}
+	if (size < 88 || le32(d) != 0 || le32(d + 4) != 0x0a4c5749u) {
+		iwl_log("firmware is not a TLV image");
 		return -1;
 	}
 	S->fw_data = d;
@@ -631,8 +771,10 @@ void iwl_stop_device(void)
 		rx_stop();
 		iwl_wr_prph(APMG_CLK_EN_REG, APMG_CLK_DMA_RQT);
 		/* Inform ME that we are leaving (7000 family). */
-		prph_set(APMG_PCIDEV_STT_REG, APMG_PCIDEV_WAKE_ME);
-		iwl_udelay(5000);
+		if (S->fam->wake_me) {
+			prph_set(APMG_PCIDEV_STT_REG, APMG_PCIDEV_WAKE_ME);
+			iwl_udelay(5000);
+		}
 	}
 	stop_master();
 	iwl_set(CSR_RESET, RESET_SW_RESET);
@@ -690,10 +832,12 @@ static int alloc_rings(void)
 				return -1;
 		}
 	}
-	if (alloc_txq(IWL_Q_CMD, CMD_SLOTS, CMD_BUF) < 0 ||
-	    alloc_txq(IWL_Q_AUX, 8, DATA_BUF) < 0 ||
-	    alloc_txq(IWL_Q_BSS, DATA_SLOTS, DATA_BUF) < 0)
+	if (alloc_txq(S->fam->cmd_q, CMD_SLOTS, CMD_BUF) < 0)
 		return -1;
+	for (i = 0; i < 4; i++)
+		if (S->fam->q[i] != 0xff &&
+		    alloc_txq(S->fam->q[i], S->fam->q_slots[i], DATA_BUF) < 0)
+			return -1;
 	return 0;
 }
 
@@ -734,7 +878,8 @@ static void tx_init(void)
 	for (q = 0; q < IWL_NUM_Q; q++)
 		if (S->q[q].tfds)
 			iwl_wr(fh_cbbc(q), (unsigned int)S->q[q].tfds >> 8);
-	prph_set(SCD_GP_CTRL, SCD_GP_AUTO_ACTIVE | SCD_GP_31_QUEUES);
+	prph_set(SCD_GP_CTRL, SCD_GP_AUTO_ACTIVE |
+		 (S->fam->nq > 20 ? SCD_GP_31_QUEUES : 0));
 }
 
 /* ---- firmware load ------------------------------------------------------ */
@@ -772,12 +917,37 @@ static int load_chunk(unsigned int dst, const unsigned char *src,
 	return 0;
 }
 
+static int load_section(unsigned int dst, const unsigned char *p,
+			unsigned int len)
+{
+	unsigned int o;
+
+	for (o = 0; o < len; o += FH_MEM_TB_MAX_LENGTH) {
+		unsigned int n = len - o;
+
+		if (n > FH_MEM_TB_MAX_LENGTH)
+			n = FH_MEM_TB_MAX_LENGTH;
+		if (load_chunk(dst + o, p + o, n) < 0)
+			return -1;
+	}
+	return 0;
+}
+
 static int load_sections(int img)
 {
 	unsigned int want = img == IWL_IMG_INIT ? TLV_SEC_INIT : TLV_SEC_RT;
 	const unsigned char *d = S->fw_data;
 	unsigned int off = 88, nsec = 0;
 
+	if (!S->fam->tlv) {
+		/* IWLAGN_RTC_INST_LOWER_BOUND / IWLAGN_RTC_DATA_LOWER_BOUND */
+		if (load_section(0x000000, S->img_inst[img],
+				 S->img_inst_len[img]) < 0 ||
+		    load_section(0x800000, S->img_data[img],
+				 S->img_data_len[img]) < 0)
+			return -1;
+		return 0;
+	}
 	while (off + 8 <= S->fw_size) {
 		unsigned int t = le32(d + off), l = le32(d + off + 4);
 		const unsigned char *p = d + off + 8;
@@ -825,10 +995,14 @@ int iwl_load_fw(int img)
 	}
 	S->fatal = 0;
 	S->waiting = 0;
+	/* iwl_op_mode_nic_config(): radio SKU bits (DVM) before the rings. */
+	if (S->nic_config)
+		S->nic_config();
 	rx_init();
 	tx_init();
-	iwl_wr(CSR_MAC_SHADOW_REG_CTRL,
-	       iwl_rd(CSR_MAC_SHADOW_REG_CTRL) | 0x800fffffu);
+	if (S->fam->shadow_reg)
+		iwl_wr(CSR_MAC_SHADOW_REG_CTRL,
+		       iwl_rd(CSR_MAC_SHADOW_REG_CTRL) | 0x800fffffu);
 	iwl_wr(CSR_UCODE_DRV_GP1_CLR, UCODE_SW_BIT_RFKILL);
 	if (load_sections(img) < 0) {
 		iwl_log("firmware section load failed");
@@ -841,34 +1015,56 @@ int iwl_load_fw(int img)
 
 /* After ALIVE: scheduler context, byte-count tables, cmd queue on FIFO 7,
  * TX DMA channels (iwl_pcie_tx_start()). */
+/* iwl_trans_pcie_txq_enable() with a cfg (the transport programs the
+ * scheduler: FIFO, window, frame limit), as iwl_trans_ac_txq_enable()
+ * does for the command queue and for DVM's AC queues. */
+static void scd_enable_queue(unsigned int qn, unsigned int fifo)
+{
+	struct txq *q = &S->q[qn];
+	int cmdq = qn == S->fam->cmd_q;
+
+	if (cmdq && S->fam->scd_set_active)
+		iwl_wr_prph(SCD_EN_CTRL, 0);
+	iwl_wr_prph(scd_queue_status(qn), 1u << SCD_STTS_ACT_EN);
+	if (!cmdq)
+		prph_set(SCD_QUEUECHAIN_SEL, 1u << qn);
+	prph_clr(SCD_AGGR_SEL, 1u << qn);
+	q->wptr = q->rptr = 0;
+	iwl_wr(HBUS_TARG_WRPTR, 0 | (qn << 8));
+	iwl_wr_prph(scd_queue_rdptr(qn), 0);
+	mem_wr32(S->scd_base + SCD_CONTEXT_MEM + qn * 8, 0);
+	mem_wr32(S->scd_base + SCD_CONTEXT_MEM + qn * 8 + 4,
+		 (64u & 0x7f) | ((64u << 16) & 0x7f0000u));
+	iwl_wr_prph(scd_queue_status(qn),
+		    (1u << SCD_STTS_ACTIVE) | (fifo << SCD_STTS_TXF) |
+		    (1u << SCD_STTS_WSL) | SCD_STTS_MSK);
+	if (cmdq && S->fam->scd_set_active)
+		iwl_wr_prph(SCD_EN_CTRL, 1u << qn);
+	q->active = 1;
+}
+
+void iwl_txq_enable_fifo(int qn, unsigned int fifo)
+{
+	if (S && qn >= 0 && qn < IWL_NUM_Q && S->q[qn].tfds)
+		scd_enable_queue((unsigned int)qn, fifo);
+}
+
 void iwl_fw_alive(unsigned int scd_base)
 {
-	struct txq *q = &S->q[IWL_Q_CMD];
 	unsigned int c;
 
 	S->scd_base = iwl_rd_prph(SCD_SRAM_BASE_ADDR);
 	if (scd_base && scd_base != S->scd_base)
 		iwl_loghex("scd base mismatch, alive says", scd_base);
 	mem_zero(S->scd_base + SCD_CONTEXT_MEM,
-		 (((SCD_TRANS_TBL_MEM + IWL_NUM_Q * 2) & 0xfffcu) -
+		 (((SCD_TRANS_TBL_MEM + S->fam->nq * 2) & 0xfffcu) -
 		  SCD_CONTEXT_MEM) / 4);
 	iwl_wr_prph(SCD_DRAM_BASE_ADDR, (unsigned int)S->bc >> 10);
+	/* The SCD chain extension misbehaves on the 6000 family. */
+	if (S->fam->chain_ext_wa)
+		iwl_wr_prph(SCD_CHAINEXT_EN, 0);
 
-	/* iwl_trans_ac_txq_enable(cmd queue, FIFO 7). */
-	iwl_wr_prph(SCD_EN_CTRL, 0);
-	iwl_wr_prph(scd_queue_status(IWL_Q_CMD), 1u << SCD_STTS_ACT_EN);
-	prph_clr(SCD_AGGR_SEL, 1u << IWL_Q_CMD);
-	q->wptr = q->rptr = 0;
-	iwl_wr(HBUS_TARG_WRPTR, 0 | (IWL_Q_CMD << 8));
-	iwl_wr_prph(scd_queue_rdptr(IWL_Q_CMD), 0);
-	mem_wr32(S->scd_base + SCD_CONTEXT_MEM + IWL_Q_CMD * 8, 0);
-	mem_wr32(S->scd_base + SCD_CONTEXT_MEM + IWL_Q_CMD * 8 + 4,
-		 (64u & 0x7f) | ((64u << 16) & 0x7f0000u));
-	iwl_wr_prph(scd_queue_status(IWL_Q_CMD),
-		    (1u << SCD_STTS_ACTIVE) | (7u << SCD_STTS_TXF) |
-		    (1u << SCD_STTS_WSL) | SCD_STTS_MSK);
-	iwl_wr_prph(SCD_EN_CTRL, 1u << IWL_Q_CMD);
-	q->active = 1;
+	scd_enable_queue(S->fam->cmd_q, S->fam->cmd_fifo);
 
 	iwl_wr_prph(SCD_TXFACT, 0xffu);                 /* FIFOs 0..7 */
 	for (c = 0; c < 8; c++)
@@ -915,8 +1111,12 @@ static void bc_set(int qn, unsigned int idx, unsigned int bytes,
 	unsigned short *t = S->bc + qn * BC_ENTRIES;
 	unsigned short v;
 
-	/* + CRC + delimiter, in dwords (bc_table_dword on 7000). */
-	v = (unsigned short)((((bytes + 8) + 3) / 4) | (sta << 12));
+	/* + CRC + delimiter; in dwords with bc_table_dword (7000), else
+	 * bytes (iwl_txq_gen1_update_byte_cnt_tbl()). */
+	bytes += 8;
+	if (S->fam->bc_dword)
+		bytes = (bytes + 3) / 4;
+	v = (unsigned short)(bytes | (sta << 12));
 	t[idx] = v;
 	if (idx < BC_ENTRIES - TFD_RING)
 		t[TFD_RING + idx] = v;
@@ -943,12 +1143,14 @@ static void ring_doorbell(int qn)
 static int enqueue_cmd(unsigned int id, const void *data, unsigned int len,
 		       unsigned short *seq_out)
 {
-	struct txq *q = &S->q[IWL_Q_CMD];
+	unsigned int cq = S->fam->cmd_q;
+	struct txq *q = &S->q[cq];
 	/* mvm sets wide_cmd_header: legacy (group 0) commands are sent as
-	 * group 1 with the 8-byte header (iwl_trans_send_cmd(), DEF_ID). */
+	 * group 1 with the 8-byte header (iwl_trans_send_cmd(), DEF_ID).
+	 * DVM uses the plain 4-byte iwl_cmd_header. */
 	unsigned char group = (id >> 8) & 0xff ? (id >> 8) & 0xff : 1;
 	unsigned char *buf, *tfd;
-	unsigned int hdr = 8, total = hdr + len, idx;
+	unsigned int hdr = S->fam->wide_hdr ? 8 : 4, total = hdr + len, idx;
 	unsigned short seq;
 
 	if (!q->active || total > CMD_BUF)
@@ -960,15 +1162,17 @@ static int enqueue_cmd(unsigned int id, const void *data, unsigned int len,
 	}
 	idx = q->wptr;
 	buf = slot_buf(q, idx);
-	seq = (unsigned short)((IWL_Q_CMD << 8) | idx);
+	seq = (unsigned short)((cq << 8) | idx);
 	buf[0] = id & 0xff;
-	buf[1] = group;
+	buf[1] = S->fam->wide_hdr ? group : 0;
 	buf[2] = seq & 0xff;
 	buf[3] = seq >> 8;
-	buf[4] = len & 0xff;
-	buf[5] = len >> 8;
-	buf[6] = 0;
-	buf[7] = (id >> 16) & 0xff;
+	if (S->fam->wide_hdr) {
+		buf[4] = len & 0xff;
+		buf[5] = len >> 8;
+		buf[6] = 0;
+		buf[7] = (id >> 16) & 0xff;
+	}
 	iwl_memcpy(buf + hdr, data, len);
 	tfd = q->tfds + idx * TFD_SIZE;
 	iwl_memzero(tfd, TFD_SIZE);
@@ -979,7 +1183,7 @@ static int enqueue_cmd(unsigned int id, const void *data, unsigned int len,
 		tfd_set(tfd, 1, (unsigned int)buf + FIRST_TB, total - FIRST_TB);
 	}
 	*seq_out = seq;
-	ring_doorbell(IWL_Q_CMD);
+	ring_doorbell(cq);
 	return 0;
 }
 
@@ -1152,7 +1356,7 @@ int iwl_send_cmd(unsigned int id, const void *data, unsigned int len,
 			iwl_udelay(100);
 	}
 	S->waiting = 0;
-	S->q[IWL_Q_CMD].rptr = S->q[IWL_Q_CMD].wptr;
+	S->q[S->fam->cmd_q].rptr = S->q[S->fam->cmd_q].wptr;
 	if (!S->resp_done) {
 		iwl_loghex("command timeout, id", id);
 		return -1;

+ 22 - 1
iwl_trans.h

@@ -1,4 +1,5 @@
-/* Intel 7265D/3165 (iwlwifi "7000" family) PCIe transport.
+/* Intel iwlwifi PCIe transport: the 7000 family (7265D/3165, MVM firmware)
+ * and the 6000 family (6200/6300, DVM firmware).
  *
  * Polled, single RX queue, gen1 TFD TX queues.  Every ring and buffer comes
  * from the page allocator (nothing big in BSS: the kernel image must stay
@@ -13,6 +14,19 @@
 #define IWL_Q_BSS   4     /* AP station: management + data */
 #define IWL_NUM_Q   31
 
+/* DVM (6000 family) queues: the four AC queues in Linux's default
+ * iwlagn_default_queue_to_tx_fifo order, command queue on 4. */
+#define IWL_DVM_Q_VO   0   /* FIFO 3: management frames */
+#define IWL_DVM_Q_VI   1   /* FIFO 2 */
+#define IWL_DVM_Q_BE   2   /* FIFO 1: non-QoS data */
+#define IWL_DVM_Q_BK   3   /* FIFO 0 */
+#define IWL_DVM_Q_CMD  4   /* IWL_DEFAULT_CMD_QUEUE_NUM, FIFO 7 */
+
+/* Device sub-families (iwl_subfamily()). */
+#define IWL_SUB_7265   1   /* 7265D / 3165: MVM firmware */
+#define IWL_SUB_6000I  2   /* 6200 (6000i): DVM, antennas B+C */
+#define IWL_SUB_6000   3   /* 6300: DVM, antennas A+B+C */
+
 /* Firmware images in the .ucode file. */
 #define IWL_IMG_RT    0
 #define IWL_IMG_INIT  1
@@ -57,6 +71,13 @@ int  iwl_start_hw(void);               /* prepare, reset, APM init */
 int  iwl_load_fw(int img);             /* rings + sections + release reset */
 void iwl_fw_alive(unsigned int scd_base); /* SCD setup + cmd queue enable */
 void iwl_stop_device(void);            /* stop DMA, APM stop (kexec, retry) */
+int  iwl_is_dvm(void);                 /* 6000 family (DVM firmware) */
+int  iwl_fatal(void);                  /* firmware crashed (SW/HW error) */
+unsigned int iwl_subfamily(void);      /* IWL_SUB_* */
+/* DVM: radio SKU / config bits written during NIC init, before rings. */
+void iwl_set_nic_config(void (*fn)(void));
+/* DVM AC queue: scheduler programmed by the transport (FIFO, window). */
+void iwl_txq_enable_fifo(int q, unsigned int fifo);
 int  iwl_rfkill(void);                 /* 1 = hardware RF-kill asserted */
 
 /* --- firmware I/O ------------------------------------------------------- */

+ 1 - 1
syscall.h

@@ -163,7 +163,7 @@
 /* Current process id (used for per-process temporary paths). */
 #define SYS_GETPID        108  /* () -> pid */
 
-/* Intel 7265D/3165 WiFi (wifi.c).  One multiplexed call: (op, a2, a3). */
+/* Intel 7265D/3165 and 6200/6300 WiFi (wifi.c).  One multiplexed call: (op, a2, a3). */
 #define SYS_WIFI          110
 #define SYS_WIFI_UP          0  /* () -> 0 / -1: load firmware, read NVM */
 #define SYS_WIFI_STATUS      1  /* (struct sys_wifi_status *out) -> 0/-1 */

+ 2 - 2
ucmd_wifi.c

@@ -1,4 +1,4 @@
-/* wifi: ring-3 WiFi command for the Intel 7265D/3165 (see wifi.c).
+/* wifi: ring-3 WiFi command for the Intel 7265D/3165 and 6200/6300 (see wifi.c).
  *
  *   wifi                         status
  *   wifi up                      load the firmware, show the MAC address
@@ -207,7 +207,7 @@ static int cmd_status(void)
 		return 1;
 	}
 	if (!st.present) {
-		u_puts("wifi: no Intel 7265/3165 card found\n");
+		u_puts("wifi: no Intel 7265/3165/6200/6300 card found\n");
 		return 1;
 	}
 	u_puts("chip:     "); u_puts(st.chip);

+ 39 - 23
wifi.c

@@ -12,7 +12,8 @@
 
 #include "wifi.h"
 #include "ccmp.h"
-#include "iwl_mvm.h"
+#include "iwl_fw.h"
+#include "iwl_mvm.h"   /* IWL_RX_* status bits, wifi_rx_frame() upcalls */
 #include "iwl_trans.h"
 #include "io.h"
 #include "mm.h"
@@ -112,6 +113,19 @@ static int alloc_buffers(void)
 	return 0;
 }
 
+/* A firmware assert (CSR_INT SW_ERR) leaves the card dead: every command
+ * times out until the image is reloaded.  Drop to DOWN so the next scan or
+ * connect runs the whole bring-up again (it also clears the fatal flag). */
+static void wifi_check_crash(void)
+{
+	if (W.state == SYS_WIFI_ST_DOWN || !iwl_fatal())
+		return;
+	serial_puts(SERIAL_COM1, "wifi: firmware crashed, reloading on next use\n");
+	iwlfw_down();
+	W.state = SYS_WIFI_ST_DOWN;
+	W.detail = "firmware crashed; reload on next use";
+}
+
 static int wifi_up(void)
 {
 	if (W.state != SYS_WIFI_ST_DOWN)
@@ -120,8 +134,8 @@ static int wifi_up(void)
 		W.detail = "out of memory";
 		return -1;
 	}
-	if (iwl_mvm_up(W.mac) < 0) {
-		W.detail = iwl_mvm_state();
+	if (iwlfw_up(W.mac) < 0) {
+		W.detail = iwlfw_state();
 		return -1;
 	}
 	W.present = 1;
@@ -250,7 +264,7 @@ static void rx_mgmt(const unsigned char *f, unsigned int len, int rssi,
 			serial_puts(SERIAL_COM1, "\n");
 			W.state = SYS_WIFI_ST_IDLE;
 			W.detail = "deauthenticated by AP";
-			iwl_mvm_disconnect();
+			iwlfw_disconnect();
 		}
 	}
 }
@@ -516,7 +530,7 @@ static int tx_data(const unsigned char *dst, unsigned int ethertype,
 	f[o++] = ethertype >> 8;
 	f[o++] = ethertype;
 	wmemcpy(f + o, payload, plen);
-	if (iwl_mvm_tx_data(f, o + plen, prot) < 0)
+	if (iwlfw_tx_data(f, o + plen, prot) < 0)
 		return -1;
 	W.tx_frames++;
 	return 0;
@@ -535,7 +549,7 @@ static int tx_mgmt_frame(unsigned int stype, const unsigned char *body,
 	wmemcpy(f + 10, W.mac, 6);
 	wmemcpy(f + 16, W.cur.bssid, 6);
 	wmemcpy(f + 24, body, blen);
-	return iwl_mvm_tx_mgmt(f, 24 + blen);
+	return iwlfw_tx_mgmt(f, 24 + blen);
 }
 
 static int wait_flag(int *flag, unsigned int ms)
@@ -543,7 +557,7 @@ static int wait_flag(int *flag, unsigned int ms)
 	unsigned int t;
 
 	for (t = 0; t < ms && !*flag; t++) {
-		if (iwl_mvm_poll() < 0)
+		if (iwlfw_poll() < 0)
 			return -1;
 		if (!*flag)
 			iwl_udelay(1000);
@@ -564,7 +578,7 @@ static int do_connect(const struct sys_wifi_connect *c)
 	if (W.state == SYS_WIFI_ST_DOWN && wifi_up() < 0)
 		return -1;
 	if (W.state >= SYS_WIFI_ST_ASSOC) {
-		iwl_mvm_disconnect();
+		iwlfw_disconnect();
 		W.state = SYS_WIFI_ST_IDLE;
 	}
 	if (c->ssid_len > 32 || c->ie_len > sizeof(c->ie) || !c->channel)
@@ -588,7 +602,7 @@ static int do_connect(const struct sys_wifi_connect *c)
 	W.sw_rx_log = W.sw_fail_log = 0;
 	W.ptk_conn = 0;
 
-	if (iwl_mvm_prepare_connect(c->bssid, c->channel, W.cur.beacon_int) < 0) {
+	if (iwlfw_prepare_connect(c->bssid, c->channel, W.cur.beacon_int) < 0) {
 		W.detail = "firmware connect setup failed";
 		return -1;
 	}
@@ -606,7 +620,7 @@ static int do_connect(const struct sys_wifi_connect *c)
 	if (!W.auth_done || W.auth_status) {
 		W.detail = W.auth_done ? "authentication refused"
 				       : "no authentication reply";
-		iwl_mvm_disconnect();
+		iwlfw_disconnect();
 		return -1;
 	}
 	/* Association request: capability, listen interval, SSID, rates,
@@ -645,12 +659,12 @@ static int do_connect(const struct sys_wifi_connect *c)
 			serial_putdec(SERIAL_COM1, W.assoc_status);
 			serial_puts(SERIAL_COM1, "\n");
 		}
-		iwl_mvm_disconnect();
+		iwlfw_disconnect();
 		return -1;
 	}
-	if (iwl_mvm_set_assoc(W.aid, W.cur.beacon_int, W.cur.dtim) < 0) {
+	if (iwlfw_set_assoc(W.aid, W.cur.beacon_int, W.cur.dtim) < 0) {
 		W.detail = "firmware association update failed";
-		iwl_mvm_disconnect();
+		iwlfw_disconnect();
 		return -1;
 	}
 	W.state = SYS_WIFI_ST_ASSOC;
@@ -669,8 +683,8 @@ static void do_disconnect(void)
 	W.ptk_conn = 0;
 	if (W.state >= SYS_WIFI_ST_ASSOC) {
 		tx_mgmt_frame(12, reason, 2);
-		iwl_mvm_poll();
-		iwl_mvm_disconnect();
+		iwlfw_poll();
+		iwlfw_disconnect();
 	}
 	if (W.state != SYS_WIFI_ST_DOWN)
 		W.state = SYS_WIFI_ST_IDLE;
@@ -701,10 +715,11 @@ static int nd_rx(unsigned char *buf, unsigned int maxlen)
 	struct rxq_slot *s;
 	unsigned int n;
 
+	wifi_check_crash();
 	if (W.state == SYS_WIFI_ST_DOWN)
 		return -1;
 	if (W.rxq_head == W.rxq_tail)
-		iwl_mvm_poll();
+		iwlfw_poll();
 	if (W.rxq_head == W.rxq_tail)
 		return -1;
 	s = &W.rxq[W.rxq_tail];
@@ -792,7 +807,7 @@ static int nd_link_up(void)
 
 const struct netdev wifi_netdev = {
 	"wifi",
-	"Intel 7265D/3165 WiFi",
+	"Intel 7265D/3165 or 6200/6300 WiFi",
 	nd_init,
 	nd_get_mac,
 	nd_rx,
@@ -813,7 +828,7 @@ const struct netdev wifi_netdev = {
 void wifi_shutdown(void)
 {
 	if (W.state != SYS_WIFI_ST_DOWN || iwl_present())
-		iwl_mvm_down();
+		iwlfw_down();
 	if (W.state != SYS_WIFI_ST_DOWN)
 		W.state = SYS_WIFI_ST_DOWN;
 }
@@ -836,6 +851,7 @@ static void copy_str(char *dst, unsigned int max, const char *src)
 
 int sys_wifi(int op, int a2, int a3)
 {
+	wifi_check_crash();
 	switch (op) {
 	case SYS_WIFI_UP:
 		if (!W.present && nd_init() < 0)
@@ -878,14 +894,14 @@ int sys_wifi(int op, int a2, int a3)
 		if (W.state >= SYS_WIFI_ST_ASSOC)
 			return -1;        /* scanning while associated: not yet */
 		W.nbss = 0;
-		return iwl_mvm_scan_start();
+		return iwlfw_scan_start();
 	case SYS_WIFI_RESULTS: {
 		unsigned int max = (unsigned int)a3, n;
 
 		if (W.state == SYS_WIFI_ST_DOWN)
 			return -1;
-		iwl_mvm_poll();
-		if (iwl_mvm_scan_running())
+		iwlfw_poll();
+		if (iwlfw_scan_running())
 			return -2;
 		if (max > W.nbss)
 			max = W.nbss;
@@ -912,7 +928,7 @@ int sys_wifi(int op, int a2, int a3)
 
 		if (W.state < SYS_WIFI_ST_ASSOC)
 			return -1;
-		iwl_mvm_poll();
+		iwlfw_poll();
 		if (W.eapq_head == W.eapq_tail)
 			return 0;
 		s = &W.eapq[W.eapq_tail];
@@ -940,7 +956,7 @@ int sys_wifi(int op, int a2, int a3)
 		if (W.state < SYS_WIFI_ST_ASSOC || !user_ok(a2, sizeof(k), 0))
 			return -1;
 		wmemcpy(&k, (const void *)a2, sizeof(k));
-		r = iwl_mvm_set_key(k.pairwise, k.keyidx, k.key,
+		r = iwlfw_set_key(k.pairwise, k.keyidx, k.key,
 				    k.pairwise ? 0 : k.rsc);
 		if (r == 0) {
 			if (k.pairwise) {

+ 1 - 1
wifi.h

@@ -1,4 +1,4 @@
-/* WiFi station (Intel 7265D/3165): 802.11 MLME, Ethernet <-> 802.11 data
+/* WiFi station (Intel 7265D/3165, 6200/6300): 802.11 MLME, Ethernet <-> 802.11 data
  * path, EAPOL queue for the ring-3 supplicant, and the `wifi` netdev.  The
  * firmware and the PCIe transport are iwl_mvm.c / iwl_trans.c. */
 #ifndef WIFI_H

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini