Intel Dual Band Wireless:FreeBSD iwm 驱动文档

来源:OSDev Wiki· 阅读原文 ↗

本页提供 freebsd iwm 驱动的基本文档,该驱动支持以下 WiFi + Bluetooth 芯片组:

  • Intel Dual Band Wireless 3160
  • Intel Dual Band Wireless 3165
  • Intel Dual Band Wireless 3168
  • Intel Dual Band Wireless 7260
  • Intel Dual Band Wireless 7265
  • Intel Dual Band Wireless 8260
  • Intel Dual Band Wireless 8265

这些笔记旨在提供驱动的概览,以便开发者可以为该芯片组实现自己的 WiFi 驱动。需要结合原始源代码使用这些笔记,才能获得所有细节。原始源代码可在以下位置找到:https://github.com/freebsd/freebsd/tree/master/sys/dev/iwm

寄存器

似乎大量工作由固件处理

- 0x000 : CSR_HW_IF_CONFIG_REG	:
   - PREPARE = 0x08000000
   - NIC_READY = 0x00400000
- 0x008 : CSR_INT:
   - Interrupt Status, same bits as CSR_INT_MASK
- 0x010 : FH_INT_STS:
   - FH interrupt status
- 0x00c : CSR_INT_MASK:
   - FW_ALIVE =    0x00000001
   - WAKEUP =      0x00000002
   - RX_CMD_RESP = 0x00000008
   - OVERHEAT =    0x00000020
   - HW_KILL =     0x00000040
   - FW_ERR =      0x02000000
   - TXQ_ADV =     0x04000000
   - FH_RX =       0x80000000
- 0x020 : CSR_RESET:
   - SW_RESET =    0x00000080
- 0x024 : CSR_GP_CNTRL:
   - HW_RF_KILL_SW = 0x08000000 
- 0x028 : 32-bit Hardware Revision Register, used to identify specific version:
   - 7000 Series Chips:
       - 31-16: Reserved
       - 15-4: Device type (see IWM_CSR_HW_REV_TYPE in if_iwmreg.h in freebsd)
       - 3-2: Revision step (A,B,C,D)
       - 1-0: Minor Revision number
       
   - 8000 Series Chips:
       - 31-16: Reserved
       - 15-4: Device type (see IWM_CSR_HW_REV_TYPE in if_iwmreg.h in freebsd)
       - 3-0: Revision step (A,B,C,D,...)
- 0x088 : CSR_MBOX_SET_REG:
       - OS_ALIVE = 0x20
- 0x0A8 : CSR_MAC_SHADOW_REG_CTRL


初始化步骤

1. 首先通过设置 CSR_HW_IF_CONFIG_REG 中的 PREPARE 和 NIC_READY 位来让 NIC 准备就绪,等待 NIC_READY 读取为已设置。

2. 通过设置 CSR_MBOX_SET_REG 中的 OS_ALIVE 位来通知操作系统已就绪

3. 开始分配各种 DMA 缓冲区

       - A buffer for firmware transfers, 0x20000 byte region, 16-byte aligned
       - A buffer for the tx scheduler, 1024-byte aligned
       - A 'keep warm' page (4096 bytes) for internal use by the device, 4096-byte aligned
       - An rx ring - 256-byte aligned
       - tx rings - 256 byte aligned

4. 启动硬件(iwm_start_hw)

   - Reset the device by setting the SW_RESET bit of CSR_RESET and waiting 10us
   - Setup and enable the associated HW_KILL interrupt.

5. 启动固件(iwm_run_init_mvm_ucode)

   - Stop if RF kill
   - Set iwm_wait_phy_db_entry to be called on notification of both IWM_INIT_COMPLETE_NOTIF and IWM_CALIB_RES_NOTIF_PHY_DB
       - Parses and stores some information regarding the PAPD (?) and TXP (?)
   - Load ucode and wait for the fw to report being alive (WIP, iwm_mvm_load_ucode_wait_alive)
       - Read the firmware (iwm_read_firmware)
           - Load firmware into driver memory
           - Parse firmware contents (WIP)
       - Set iwm_alive_fn to be called on notification of MVM_ALIVE
       - Start the firmware (WIP, iwm_start_fw)
           - Check if NIC_READY bit is set, if not, redo step 1
           - Clear interrupt flags, disable interrupts
           - Ensure rfkill handshake is clear
               - Set RFKILL bit in CSR_UCODE_DRV_GP1_CLR
               - Set CMD_BLOCKED bit in CSR_UCODE_DRV_GP1_CLR
           - Init the NIC (iwm_nic_init)
               - Configure NIC (WIP, iwm_mvm_nic_config)
                   - Get the radio information (currently from the firmware, as we haven't read the nvm yet) and configure the NIC's radios appropriately
               - Setup RX queues (WIP, iwm_nic_rx_init)
                   - Stop RX dma (iwm_pcie_rx_stop)
                   - Reset pointers
                   - Set physical address of RX ring
                   - Set physical address of RX status
                   - Enable RX DMA
                   - Set the RB count
               - Setup TX queues (WIP, iwm_nic_tx_init)
                   - Deactivate TX scheduler (write 0 to peripheral register, SCD_TXFACT)
                   - Set physical address of 'keep warm' page
                   - Set physical addresses of TX rings
                   - Set queues to auto-activate (set bit 18 of peripheral register, SCD_GP_CTRL)
               - Enable MAC shadow registers by writing 0x800fffff to CSR_MAC_SHADOW_REG_CTRL
           - Disable all interrupts besides FH_TX
           - Ensure rfkill handshake is still clear
           - Load the firmware (WIP, iwm_pcie_load_given_ucode, iwm_pcie_load_given_ucode_8000)
               - For 7000 Series
                   - Load the cpu sections (iwm_pcie_load_cpu_sections)
                       - See 'Firmware Transfers' section for details.
                   - If dual CPU
                       - Write the CPU2 header address
                       - Load the cpu sections for cpu2 (WIP, iwm_pcie_load_cpu_sections)
                   - Re-enable interrupts
                   - Release the CPUs from reset (Set CSR_RESET to 0)
               - For 8000 Series
                   - 
       - Wait for MVM_ALIVE notification
       - Setup the tx scheduler (WIP, iwm_trans_pcie_fw_alive)
       - Configure firmware paging if necessary, based on the ucode information (WIP, iwm_save_fw_paging, iwm_send_paging_cmd)
   - Initialize nvm/eeprom (WIP, iwm_nvm_init)
       - Reads and parses EEPROM
   - Initialize Bluetooth config (WIP, iwm_send_bt_init_conf)
       - Sends Bluetooth initialization command
   - Get valid TX antennas (WIP, iwm_mvm_get_valid_tx_ant)
       - Part of the information obtained from the eeprom
   - Send valid TX antennas (WIP, iwm_send_tx_ant_cfg)
       - Sends a command with the previously obtained antenna configuration
   - Send physical config command to initialize ucode, and start callibrations (WIP, iwm_send_phy_cfg_cmd)
       - Sends PHY_CONFIGURATION command
   - Wait for init notification
       - Wait for callibration complete notification

6. 初始化信道映射(WIP,iwm_init_channel_map)

   - Parse nvm data to determine the supported channels and wifi bands supported by the device

7. 附加 radiotap 并注册到 WiFi 协议栈(WIP,iwm_radiotap_attach)


扫描步骤

1. 如果固件报告支持 UMAC 扫描:

   Setup a scan command with the desired scan channels and send to the device

2. 否则,如果固件报告支持 LMAC 扫描:

   Setup a scan command with the desired scan channels and send to the device


发送步骤

填充要发送给固件的 tx 命令,必要时对帧进行加密


固件传输

固件传输通过单独的 DMA 引擎完成。 各部分以 0x20000 字节为块发送给它。

超过 0x40000 且低于 0x57fff 的目标偏移被视为扩展内存。

目标偏移 0xFFFFCCCC 指定 CPU1 和 CPU2 分隔部分。 目标偏移 0xAAAABBBB 指定分页分隔部分。

有关如何编程 DMA 引擎的更多信息,请参阅 iwm_pcie_load_firmware_chunk。


TX/TFD 调度器

每个 TX 调度器条目采用以下格式:

struct tx_scheduler_entry {
   struct {
       uint16_t tx_cmd_byte_count : 12;
       uint16_t station_idx : 4;
   } tfd_queue[256 + 64];
}

tx_scheduler_entry 结构的数量与队列数量相同(MAX_QUEUES = 31)。

每个 TFD 队列的最大条目数为 256,freebsd 驱动还添加了 64 个 'BC_DUP' 条目,原因目前未知。


TX 环

共有 256 个 TX 环,每个环具有以下结构:

struct tx_ring_entry {
   uint32_t lo_addr;
   uint16_t hi_addr : 4;
   uint16_t tx_buf_len : 12;
} PACKED


lo_addr : lo component of the DMA buffer address
hi_addr : hi component of the DMA buffer address 
tx_buf_len : length of the DMA buffer

此外,每个环都有一个用于向固件提交命令的命令缓冲区。

有两种命令格式:

struct tx_cmd {
   struct cmd_hdr hdr;
   uint8_t data[320];
}


struct tx_cmd_wide {
   struct cmd_hdr_wide hdr;
   uint8_t data[316];
}


命令头

struct cmd_hdr {
   uint8_t opcode;
   uint8_t flags;
   uint8_t index;
   uint8_t queue_id;
}


struct cmd_hdr_wide {
   uint8_t opcode;
   uint8_t group_id;
   uint8_t index;
   uint8_t queue_id;
   uint16_t length;
   uint8_t rsv;
   uint8_t ver;
}


RX 环(256 字节对齐)

最多有 4096 个 RX 环(仅支持 2 的幂大小),由 32 位地址数组表示,每个环条目有一个字节对齐的 32 位地址指向一个 RX 缓冲区。(RX_BUFFER_SIZE = 4096 或 8192 或 16384)

RX 状态区域(16 字节对齐)

这是一个单一区域,采用以下格式:

struct rx_status {
   uint16_t closed_rb_num;
   uint16_t closed_frame_num;
   uint16_t finished_rb_num;
   uint16_t finished_frame_num;
   uint32_t rsv;
}


closed_rb_num [0:11] : the index of the reserve buffer that was last closed
closed_frame_num [0:11] : the index of the frame that was last closed
finished_rb_num [0:11] : the index of the current reserve buffer, to which the previous frame was written
finished_frame_num [0:11] : the index of the frame which was last transferred

RF 硬件开关禁用功能

读取 CSR_GP_CNTRL 中的 HW_RF_KILL_SW 位以获取开关状态,

   0 = RF kill is on, turn off radio
   1 = RF kill is off, can turn on radio


通知机制

与固件相关的通信全部通过队列完成,设备通过 rx 环发送响应命令来响应。freebsd 驱动将这些命令排入通知队列。

固件解析

uCode 格式

#define UCODE_MAGIC 0x0a4c5749

struct ucode_hdr {
   uint32_t zr0;
   uint32_t magic;
   uint8_t name[64];
   uint32_t version;
   uint32_t build;
   uint64_t rsv;
   uint8_t data[0];
}


struct ucode_tlv {
   uint32_t type;
   uint32_t length;
   uint8_t data[0];
}
enum ucode_tlv_type {
   UCODE_TLV_INVALID = 0,
   UCODE_TLV_INST = 1,
   UCODE_TLV_DATA = 2,
   UCODE_TLV_INIT = 3,
   UCODE_TLV_INIT_DATA = 4,
   UCODE_TLV_BOOT = 5,
   UCODE_TLV_PROBE_MAX_LEN = 6,
   UCODE_TLV_PAN = 7,
   UCODE_TLV_RUNT_EVTLOG_PTR = 8,
   UCODE_TLV_RUNT_EVTLOG_SIZE = 9,
   UCODE_TLV_RUNT_ERRLOG_PTR = 10,
   UCODE_TLV_INIT_EVTLOG_PTR = 11,
   UCODE_TLV_INIT_EVTLOG_SIZE = 12,
   UCODE_TLV_INIT_ERRLOG_PTR = 13,
   UCODE_TLV_ENHANCE_SENS_TBL = 14,
   UCODE_TLV_PHY_CALIBRATION_SIZE = 15,
   UCODE_TLV_WOWLAN_INST = 16,
   UCODE_TLV_WOWLAN_DATA = 17,
   UCODE_TLV_FLAGS = 18,
   UCODE_TLV_SEC_RT = 19,
   UCODE_TLV_SEC_INIT = 20,
   UCODE_TLV_SEC_WOWLAN = 21,
   UCODE_TLV_DEF_CALIB = 22,
   UCODE_TLV_PHY_SKU = 23,
   UCODE_TLV_SECURE_SEC_RT = 24,
   UCODE_TLV_SECURE_SEC_INIT = 25,
   UCODE_TLV_SECURE_SEC_WOWLAN = 26,
   UCODE_TLV_NUM_OF_CPU = 27,
   UCODE_TLV_CSCHEME = 28,
   UCODE_TLV_API_CHANGES_SET = 29,
   UCODE_TLV_ENABLED_CAPABILITIES = 30,
   UCODE_TLV_N_SCAN_CHANNELS = 31,
   UCODE_TLV_PAGING = 32,
   UCODE_TLV_SEC_RT_USNIFFER = 34,
   UCODE_TLV_SDIO_ADMA_ADDR = 35,
   UCODE_TLV_FW_VERSION = 36,
   UCODE_TLV_FW_DBG_DEST = 38,
   UCODE_TLV_FW_DBG_CONF = 39,
   UCODE_TLV_FW_DBG_TRIGGER = 40,
   UCODE_TLV_FW_GSCAN_CAPA = 50,
   UCODE_TLV_FW_MEM_SEG = 51,
}

示例解析代码位于 https://gitlab.com/hgoel0974/iwifi_fw_parser

来源与翻译说明

本文根据原文快照翻译,保留原有代码、数值、技术限定及历史背景。原文中的命令与运行结果不代表本站已实际执行验证。

原文:Intel Dual Band Wireless;离线修订号:30414。对应原文版本

原作者:OSDev Wiki 社区贡献者。原文及引用资料的版权与许可声明继续适用:版权声明 许可说明

评论

暂无评论