From 7969acba28822bdc9dd4649a257a1b37e368431c Mon Sep 17 00:00:00 2001 From: VasilyZa <450270247@qq.com> Date: Sun, 15 Nov 2026 14:27:49 +0800 Subject: [PATCH] net: add VMXNET3 MSI-X receive processing --- Documentation/core-api/vmxnet3.rst | 50 ++++- .../locale/en/LC_MESSAGES/core-api/vmxnet3.po | 164 ++++++++++++----- .../locale/ja/LC_MESSAGES/core-api/vmxnet3.po | 131 ++++++++++---- arch/x86_64/platform/pci.c | 12 ++ arch/x86_64/platform/pci_irq.c | 171 ++++++++++++++++-- drivers/net/vmxnet3/Kbuild | 2 +- drivers/net/vmxnet3/hardware.c | 35 +++- drivers/net/vmxnet3/internal.h | 41 ++++- drivers/net/vmxnet3/interrupt.c | 111 ++++++++++++ drivers/net/vmxnet3/main.c | 17 +- drivers/net/vmxnet3/rings.c | 61 +++++-- include/reliefnt/deferred.h | 3 +- include/reliefnt/driver_resources.h | 12 +- include/reliefnt/net.h | 6 + include/reliefnt/net_device.h | 18 ++ include/reliefnt/pci.h | 10 + include/reliefnt/pci_irq.h | 28 ++- kernel/device/api.c | 14 ++ kernel/device/driver_resources.c | 19 +- kernel/device/services.c | 75 +++++++- kernel/workqueue/services.c | 9 +- net/input.c | 36 ++++ tools/test_net_rx_budget.py | 17 ++ tools/test_pci_msix.py | 17 ++ tools/test_vmxnet3.py | 2 +- tools/tests/host-suites.list | 2 + tools/tests/ipv6_protocol_test.c | 5 + tools/tests/net_device_test.c | 22 +++ tools/tests/net_rx_budget_test.c | 69 +++++++ tools/tests/pci_msix_test.c | 89 +++++++++ tools/tests/vmxnet3_perf_guest.c | 120 ++++++++++++ tools/tests/vmxnet3_test.c | 114 +++++++++++- 32 files changed, 1331 insertions(+), 151 deletions(-) create mode 100644 drivers/net/vmxnet3/interrupt.c create mode 100644 tools/test_net_rx_budget.py create mode 100644 tools/test_pci_msix.py create mode 100644 tools/tests/net_rx_budget_test.c create mode 100644 tools/tests/pci_msix_test.c create mode 100644 tools/tests/vmxnet3_perf_guest.c diff --git a/Documentation/core-api/vmxnet3.rst b/Documentation/core-api/vmxnet3.rst index 9f1aac9a..93906889 100644 --- a/Documentation/core-api/vmxnet3.rst +++ b/Documentation/core-api/vmxnet3.rst @@ -9,9 +9,34 @@ VMXNET3 网络驱动 驱动选择 VMXNET3 revision 1 和 UPT 1,使用一条发送队列和一条接收 队列,不启用校验和、分段、VLAN 剥离、RSS 或 LRO 等硬件卸载。接口 -使用 1500 字节 MTU、软件协议校验和及轮询完成队列;中断保持屏蔽。 +使用 1500 字节 MTU 和软件协议校验和。 目的地址过滤允许本站单播、广播和所有多播,以支持 IPv6 邻居发现。 +中断与收发调度 +============== + +驱动查询设备的中断偏好,优先使用一个 MSI-X 表项,其次使用 MSI;设备 +明确要求 MSI 时直接尝试 MSI。不支持消息中断、分配失败或设备要求 INTx +时保留轮询回退,并保持设备中断屏蔽,不猜测共享 INTx 路由。消息中断 +路由到 BSP,发送、接收和控制事件共用一个向量。MSI 与 MSI-X 共用 +16 个向量,每个向量在一次启动内不复用;耗尽时新设备回退到轮询。 + +IRQ 回调仅屏蔽设备中断、刷新 posted write 并通知核心,不解析协议包。 +核心以不复用的 ifindex 合并通知,不在排队期间保存模块回调或设备指针。 +任务上下文每轮最多检查 32 个接收描述符,每张网卡连续最多检查 8 个, +满预算时重新排队;空队列才重新打开中断,并在打开后复查代际位,避免 +丢失检查空队列期间到达的数据。原有协议维护心跳和同步轮询路径继续保留。 + +任务上下文消费并确认设备事件,包括 carrier 变化和队列错误。通知路径 +不以旧 carrier 状态阻挡设备回调,否则链路恢复事件本身无法被处理。 +行政关闭的接口仍排空和重新启用中断,但不把收到的数据投递到协议层。 +中断模式使用事件更新的 carrier 缓存,轮询模式继续查询设备;接收服务 +也回收发送完成。补充接收描述符时,仅在设备设置 ``updateRxProd`` 时 +写 producer doorbell,减少每个包的 MMIO;初次投递仍显式通知设备。 + +资源与错误处理 +============== + 共享配置和环采用设备约定的 DMA 地址及代际位,发送完成须对应最早 尚未回收的描述符;接收完成须指向本队列预期的缓冲区。异常索引或 完成类型使该设备停止接收新的报文,避免复用不可信的 DMA 缓冲区。 @@ -19,16 +44,31 @@ QEMU 的 VMXNET3 模型将接收完成类型字段保留为零,驱动同时兼 该取值与设备协议的接收完成类型。驱动不接受分片报文,并在错误或 长度超出缓冲区时丢弃对应完成。 -设备停止时先同步 quiesce 和 reset,再关闭 PCI bus master 并回读; +每次回调均保留实际设备 owner。设备停止时先关闭接入、屏蔽并排空 IRQ, +再同步 quiesce 和 reset,关闭 PCI bus master 并回读; 未能证明停止时保留 DMA/MMIO 和模块所有权,以便管理器重试,而不 释放仍可能被访问的内存。设备命令是同步 MMIO 操作,队列满时发送 返回 ``EAGAIN``,不会无限等待硬件进度。 +验证 +==== + ``tools/test_vmxnet3.py`` 编译真实驱动主体并模拟 PCI、MMIO 与 DMA 边界,覆盖版本协商、链路、收发环回绕、错误完成、资源回滚、失败 -STOP 保留和多设备隔离。QEMU/KVM 测试使用两张 VMXNET3 和一张 -e1000e,验证 DHCP、IPv4/IPv6、并发 TCP/UDP 数据和模块卸载、重载。 -宿主模型和 QEMU 不能代替 VMware 实际环境验证;物理硬件也未验证。 +STOP 保留和多设备隔离,以及 MSI-X/MSI/轮询选择、中断重新打开竞态、 +carrier 事件和 producer doorbell 条件。``tools/test_pci_msix.py`` 检查 +MSI-X 表与 PBA 的 BAR 边界、重叠、映射失败、表项屏蔽和旧向量隔离; +``tools/test_net_rx_budget.py`` 检查描述符预算与网卡之间的公平调度。 + +ReliefOS 的 ``tools/test_vmxnet3_qemu.py`` 使用两张 VMXNET3 和一张 +e1000e,验证 DHCP、IPv4/IPv6、并发 TCP/UDP、真实 MSI-X 计数及模块 +卸载、重载。``tools/tests/vmxnet3_perf_guest.c`` 通过标准 socket 验证 +全部 TCP 回显字节和 UDP 数据,供父仓性能编排比较耗时、CPU 统计和 +往返延迟。吞吐按单方向的回显有效载荷计算,不是双向加总或网卡线速。 + +QEMU 性能、VMware 基础联网、模块生命周期和长时间负载须分别记录, +不能互相代替。宿主模型和 QEMU 不能代替 VMware 实际环境验证; +物理硬件也未验证。此内部驱动与调度接口不扩展 Linux/POSIX 用户态 ABI。 协议字段根据 VMware Linux 驱动定义及 QEMU 的 VMXNET3 设备实现 核对:`Linux vmxnet3_defs.h `_、 diff --git a/Documentation/locale/en/LC_MESSAGES/core-api/vmxnet3.po b/Documentation/locale/en/LC_MESSAGES/core-api/vmxnet3.po index 681f93dd..41b1e890 100644 --- a/Documentation/locale/en/LC_MESSAGES/core-api/vmxnet3.po +++ b/Documentation/locale/en/LC_MESSAGES/core-api/vmxnet3.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: ReliefNT 5.3.2\n" -"Report-Msgid-Bugs-To:\n" +"Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-11-14 23:58+0800\n" "PO-Revision-Date: 2026-11-14 00:00+0800\n" "Last-Translator: ReliefOS contributors\n" @@ -34,18 +34,6 @@ msgstr "" "interface; the interfaces use the existing network-device API and " "IPv4/IPv6 stack." -msgid "" -"驱动选择 VMXNET3 revision 1 和 UPT 1,使用一条发送队列和一条接收 队列,不启用校验和、分段、VLAN 剥离、RSS 或 " -"LRO 等硬件卸载。接口 使用 1500 字节 MTU、软件协议校验和及轮询完成队列;中断保持屏蔽。 " -"目的地址过滤允许本站单播、广播和所有多播,以支持 IPv6 邻居发现。" -msgstr "" -"The driver selects VMXNET3 revision 1 and UPT 1 and uses one transmit " -"queue and one receive queue, without hardware offloads such as checksums," -" segmentation, VLAN stripping, RSS, or LRO. The interface uses a " -"1500-byte MTU, software protocol checksums, and polled completion queues;" -" interrupts remain masked. Destination-address filtering accepts local " -"unicast, broadcast, and all multicast to support IPv6 neighbor discovery." - msgid "" "共享配置和环采用设备约定的 DMA 地址及代际位,发送完成须对应最早 尚未回收的描述符;接收完成须指向本队列预期的缓冲区。异常索引或 " "完成类型使该设备停止接收新的报文,避免复用不可信的 DMA 缓冲区。 QEMU 的 VMXNET3 模型将接收完成类型字段保留为零,驱动同时兼容 " @@ -61,34 +49,6 @@ msgstr "" "receive-completion type. The driver does not accept fragmented packets " "and discards completions with errors or lengths exceeding the buffer." -msgid "" -"设备停止时先同步 quiesce 和 reset,再关闭 PCI bus master 并回读; 未能证明停止时保留 DMA/MMIO " -"和模块所有权,以便管理器重试,而不 释放仍可能被访问的内存。设备命令是同步 MMIO 操作,队列满时发送 返回 " -"``EAGAIN``,不会无限等待硬件进度。" -msgstr "" -"When stopping a device, the driver first synchronously quiesces and " -"resets it, then disables PCI bus mastering and reads it back. If it " -"cannot prove that the device stopped, it retains DMA/MMIO resources and " -"module ownership for a manager retry rather than freeing memory that may " -"still be accessed. Device commands are synchronous MMIO operations; " -"transmission returns ``EAGAIN`` when the queue is full instead of waiting" -" indefinitely for hardware progress." - -msgid "" -"``tools/test_vmxnet3.py`` 编译真实驱动主体并模拟 PCI、MMIO 与 DMA " -"边界,覆盖版本协商、链路、收发环回绕、错误完成、资源回滚、失败 STOP 保留和多设备隔离。QEMU/KVM 测试使用两张 VMXNET3 和一张" -" e1000e,验证 DHCP、IPv4/IPv6、并发 TCP/UDP 数据和模块卸载、重载。 宿主模型和 QEMU 不能代替 VMware " -"实际环境验证;物理硬件也未验证。" -msgstr "" -"``tools/test_vmxnet3.py`` compiles the real driver and simulates the PCI," -" MMIO, and DMA boundaries, covering version negotiation, link state, " -"transmit and receive ring wraparound, erroneous completions, resource " -"rollback, retained resources after a failed STOP, and isolation between " -"devices. A QEMU/KVM test with two VMXNET3 adapters and one e1000e checks " -"DHCP, IPv4/IPv6, concurrent TCP/UDP traffic, and module unload and " -"reload. Host models and QEMU do not replace validation in an actual " -"VMware environment; physical hardware has not been validated either." - msgid "" "协议字段根据 VMware Linux 驱动定义及 QEMU 的 VMXNET3 设备实现 核对:`Linux vmxnet3_defs.h " "`_、" @@ -104,3 +64,125 @@ msgstr "" "implementation in this directory is original ReliefNT code under " "Apache-2.0 and does not contain implementation code from those GPL source" " files." + +msgid "" +"驱动选择 VMXNET3 revision 1 和 UPT 1,使用一条发送队列和一条接收 队列,不启用校验和、分段、VLAN 剥离、RSS 或 " +"LRO 等硬件卸载。接口 使用 1500 字节 MTU 和软件协议校验和。 目的地址过滤允许本站单播、广播和所有多播,以支持 IPv6 邻居发现。" +msgstr "" +"The driver selects VMXNET3 revision 1 and UPT 1 and uses one transmit " +"queue and one receive queue, without hardware offloads such as checksums," +" segmentation, VLAN stripping, RSS, or LRO. The interface uses a " +"1500-byte MTU and software protocol checksums. Destination-address " +"filtering accepts local unicast, broadcast, and all multicast to support " +"IPv6 neighbor discovery." + +msgid "中断与收发调度" +msgstr "Interrupts and packet scheduling" + +msgid "" +"驱动查询设备的中断偏好,优先使用一个 MSI-X 表项,其次使用 MSI;设备 明确要求 MSI 时直接尝试 " +"MSI。不支持消息中断、分配失败或设备要求 INTx 时保留轮询回退,并保持设备中断屏蔽,不猜测共享 INTx 路由。消息中断 路由到 " +"BSP,发送、接收和控制事件共用一个向量。MSI 与 MSI-X 共用 16 个向量,每个向量在一次启动内不复用;耗尽时新设备回退到轮询。" +msgstr "" +"The driver queries the device interrupt preference, trying one MSI-X " +"entry first and then MSI; an explicit MSI preference skips MSI-X. If " +"message interrupts are unavailable, allocation fails, or the device " +"requests INTx, it retains a polling fallback with device interrupts " +"masked rather than guessing shared INTx routing. Messages target the BSP," +" with transmit, receive, and control events sharing one vector. MSI and " +"MSI-X share 16 vectors, each used only once per boot; new devices fall " +"back to polling when this pool is exhausted." + +msgid "" +"IRQ 回调仅屏蔽设备中断、刷新 posted write 并通知核心,不解析协议包。 核心以不复用的 ifindex " +"合并通知,不在排队期间保存模块回调或设备指针。 任务上下文每轮最多检查 32 个接收描述符,每张网卡连续最多检查 8 个, " +"满预算时重新排队;空队列才重新打开中断,并在打开后复查代际位,避免 丢失检查空队列期间到达的数据。原有协议维护心跳和同步轮询路径继续保留。" +msgstr "" +"The IRQ callback only masks the device interrupt, flushes the posted " +"write, and notifies the core; it does not parse packets. The core " +"coalesces notifications by never-reused ifindex, without storing module " +"callbacks or device pointers while queued. Task context checks at most 32" +" receive descriptors per turn and at most 8 consecutively per NIC, " +"requeuing when the budget is used. It rearms interrupts only after " +"observing an empty queue and rechecks generation bits after rearming to " +"avoid losing packets arriving during the empty check. Existing protocol " +"maintenance heartbeats and synchronous polling remain available." + +msgid "" +"任务上下文消费并确认设备事件,包括 carrier 变化和队列错误。通知路径 不以旧 carrier " +"状态阻挡设备回调,否则链路恢复事件本身无法被处理。 行政关闭的接口仍排空和重新启用中断,但不把收到的数据投递到协议层。 中断模式使用事件更新的 " +"carrier 缓存,轮询模式继续查询设备;接收服务 也回收发送完成。补充接收描述符时,仅在设备设置 ``updateRxProd`` 时 写 " +"producer doorbell,减少每个包的 MMIO;初次投递仍显式通知设备。" +msgstr "" +"Task context consumes and acknowledges device events, including carrier " +"changes and queue faults. Notification processing does not gate callbacks" +" on stale carrier state, since a link-up event itself needs service. " +"Administratively down interfaces still drain and rearm interrupts but do " +"not deliver received packets to the protocol stack. Interrupt mode uses " +"an event-updated carrier cache; polling mode continues querying the " +"device. Receive service also reclaims transmit completions. Refilled " +"receive descriptors ring the producer doorbell only when the device sets " +"``updateRxProd``, reducing per-packet MMIO; initial posting still " +"explicitly notifies the device." + +msgid "资源与错误处理" +msgstr "Resources and error handling" + +msgid "" +"每次回调均保留实际设备 owner。设备停止时先关闭接入、屏蔽并排空 IRQ, 再同步 quiesce 和 reset,关闭 PCI bus " +"master 并回读; 未能证明停止时保留 DMA/MMIO 和模块所有权,以便管理器重试,而不 释放仍可能被访问的内存。设备命令是同步 MMIO" +" 操作,队列满时发送 返回 ``EAGAIN``,不会无限等待硬件进度。" +msgstr "" +"Every callback pins the actual device owner. Stopping a device first " +"closes callback admission, masks interrupts, and drains IRQ callbacks, " +"then synchronously quiesces and resets it before disabling PCI bus " +"mastering and reading it back. If stopping cannot be proven, DMA/MMIO " +"resources and module ownership are retained for a manager retry rather " +"than freeing memory that may still be accessed. Device commands use " +"synchronous MMIO; a full transmit queue returns ``EAGAIN`` instead of " +"waiting indefinitely for hardware progress." + +msgid "验证" +msgstr "Validation" + +msgid "" +"``tools/test_vmxnet3.py`` 编译真实驱动主体并模拟 PCI、MMIO 与 DMA " +"边界,覆盖版本协商、链路、收发环回绕、错误完成、资源回滚、失败 STOP 保留和多设备隔离,以及 MSI-X/MSI/轮询选择、中断重新打开竞态、" +" carrier 事件和 producer doorbell 条件。``tools/test_pci_msix.py`` 检查 MSI-X 表与 " +"PBA 的 BAR 边界、重叠、映射失败、表项屏蔽和旧向量隔离; ``tools/test_net_rx_budget.py`` " +"检查描述符预算与网卡之间的公平调度。" +msgstr "" +"``tools/test_vmxnet3.py`` compiles the real driver against modeled PCI, " +"MMIO, and DMA boundaries. It covers negotiation, carrier, ring " +"wraparound, malformed completions, resource rollback, failed-STOP " +"retention, device isolation, MSI-X/MSI/polling selection, interrupt rearm" +" races, carrier events, and producer doorbell conditions. " +"``tools/test_pci_msix.py`` checks MSI-X table/PBA BAR bounds, overlap, " +"mapping failures, entry masks, and retired-vector isolation; " +"``tools/test_net_rx_budget.py`` checks descriptor budgets and fairness " +"between NICs." + +msgid "" +"ReliefOS 的 ``tools/test_vmxnet3_qemu.py`` 使用两张 VMXNET3 和一张 e1000e,验证 " +"DHCP、IPv4/IPv6、并发 TCP/UDP、真实 MSI-X 计数及模块 " +"卸载、重载。``tools/tests/vmxnet3_perf_guest.c`` 通过标准 socket 验证 全部 TCP 回显字节和 " +"UDP 数据,供父仓性能编排比较耗时、CPU 统计和 往返延迟。吞吐按单方向的回显有效载荷计算,不是双向加总或网卡线速。" +msgstr "" +"ReliefOS uses ``tools/test_vmxnet3_qemu.py`` with two VMXNET3 adapters " +"and one e1000e to check DHCP, IPv4/IPv6, concurrent TCP/UDP, actual MSI-X" +" counts, and module unload/reload. ``tools/tests/vmxnet3_perf_guest.c`` " +"uses standard sockets to verify every echoed TCP byte and UDP payload for" +" the parent repository benchmark, comparing elapsed time, CPU accounting," +" and round-trip latency. Throughput counts echo payload in one direction," +" not the sum of both directions or NIC line rate." + +msgid "" +"QEMU 性能、VMware 基础联网、模块生命周期和长时间负载须分别记录, 不能互相代替。宿主模型和 QEMU 不能代替 VMware " +"实际环境验证; 物理硬件也未验证。此内部驱动与调度接口不扩展 Linux/POSIX 用户态 ABI。" +msgstr "" +"QEMU performance, basic VMware networking, module lifecycle, and " +"sustained-load validation must be recorded separately; none substitutes " +"for another. Host models and QEMU do not replace an actual VMware " +"environment, and physical hardware has not been validated. These internal" +" driver and scheduling interfaces do not extend the Linux/POSIX userspace" +" ABI." diff --git a/Documentation/locale/ja/LC_MESSAGES/core-api/vmxnet3.po b/Documentation/locale/ja/LC_MESSAGES/core-api/vmxnet3.po index 86b9820f..dfe1403c 100644 --- a/Documentation/locale/ja/LC_MESSAGES/core-api/vmxnet3.po +++ b/Documentation/locale/ja/LC_MESSAGES/core-api/vmxnet3.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: ReliefNT 5.3.2\n" -"Report-Msgid-Bugs-To:\n" +"Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-11-14 23:58+0800\n" "PO-Revision-Date: 2026-11-14 00:00+0800\n" "Last-Translator: ReliefOS contributors\n" @@ -33,17 +33,6 @@ msgstr "" "リングと制御状態を独立して確保し、ネットワークインターフェースを一つ登録します。これらは既存のネットワークデバイスインターフェースと " "IPv4/IPv6 スタックを使用します。" -msgid "" -"驱动选择 VMXNET3 revision 1 和 UPT 1,使用一条发送队列和一条接收 队列,不启用校验和、分段、VLAN 剥离、RSS 或 " -"LRO 等硬件卸载。接口 使用 1500 字节 MTU、软件协议校验和及轮询完成队列;中断保持屏蔽。 " -"目的地址过滤允许本站单播、广播和所有多播,以支持 IPv6 邻居发现。" -msgstr "" -"ドライバーは VMXNET3 revision 1 と UPT 1 " -"を選択し、送信キューと受信キューを各一つ使用します。チェックサム、セグメンテーション、VLAN 除去、RSS、LRO " -"などのハードウェアオフロードは有効にしません。インターフェースは 1500 バイトの " -"MTU、ソフトウェアによるプロトコルチェックサム、ポーリングによる完了キューを使用し、割り込みはマスクしたままです。宛先アドレスフィルターは " -"IPv6 の近隣探索を支えるため、自局ユニキャスト、ブロードキャスト、すべてのマルチキャストを許可します。" - msgid "" "共享配置和环采用设备约定的 DMA 地址及代际位,发送完成须对应最早 尚未回收的描述符;接收完成须指向本队列预期的缓冲区。异常索引或 " "完成类型使该设备停止接收新的报文,避免复用不可信的 DMA 缓冲区。 QEMU 的 VMXNET3 模型将接收完成类型字段保留为零,驱动同时兼容 " @@ -54,28 +43,6 @@ msgstr "" " DMA バッファーの再利用を防ぎます。QEMU の VMXNET3 " "モデルでは受信完了種別フィールドがゼロのままになるため、ドライバーはその値とデバイスプロトコルの受信完了種別の両方に対応します。分割されたパケットは受け付けず、エラーがある場合や長さがバッファーを超える場合は該当する完了を破棄します。" -msgid "" -"设备停止时先同步 quiesce 和 reset,再关闭 PCI bus master 并回读; 未能证明停止时保留 DMA/MMIO " -"和模块所有权,以便管理器重试,而不 释放仍可能被访问的内存。设备命令是同步 MMIO 操作,队列满时发送 返回 " -"``EAGAIN``,不会无限等待硬件进度。" -msgstr "" -"デバイスの停止時には、まず同期的に quiesce と reset を実行し、続いて PCI " -"バスマスターを無効化して読み戻します。停止を確認できない場合、まだアクセスされる可能性のあるメモリーを解放せず、管理側が再試行できるよう " -"DMA/MMIO とモジュールの所有権を保持します。デバイスコマンドは同期 MMIO " -"操作です。キューが満杯の場合、送信はハードウェアの進行を無期限に待たず ``EAGAIN`` を返します。" - -msgid "" -"``tools/test_vmxnet3.py`` 编译真实驱动主体并模拟 PCI、MMIO 与 DMA " -"边界,覆盖版本协商、链路、收发环回绕、错误完成、资源回滚、失败 STOP 保留和多设备隔离。QEMU/KVM 测试使用两张 VMXNET3 和一张" -" e1000e,验证 DHCP、IPv4/IPv6、并发 TCP/UDP 数据和模块卸载、重载。 宿主模型和 QEMU 不能代替 VMware " -"实际环境验证;物理硬件也未验证。" -msgstr "" -"``tools/test_vmxnet3.py`` は実際のドライバー本体をコンパイルし、PCI、MMIO、DMA " -"の境界を模擬します。バージョン交渉、リンク状態、送受信リングの周回、異常な完了、リソースのロールバック、STOP " -"失敗時の保持、複数デバイス間の分離を検証します。VMXNET3 2 台と e1000e 1 台を使う QEMU/KVM " -"テストでは、DHCP、IPv4/IPv6、並行 TCP/UDP 通信、モジュールのアンロードと再ロードを確認します。ホストモデルと QEMU " -"は実際の VMware 環境での検証に代わるものではなく、実機も未検証です。" - msgid "" "协议字段根据 VMware Linux 驱动定义及 QEMU 的 VMXNET3 设备实现 核对:`Linux vmxnet3_defs.h " "`_、" @@ -89,3 +56,99 @@ msgstr "" " vmxnet3.c `_ " "を参照してください。このディレクトリの実装は Apache-2.0 に従う ReliefNT 独自のコードであり、上記 GPL " "ソースファイルの実装コードは含みません。" + +msgid "" +"驱动选择 VMXNET3 revision 1 和 UPT 1,使用一条发送队列和一条接收 队列,不启用校验和、分段、VLAN 剥离、RSS 或 " +"LRO 等硬件卸载。接口 使用 1500 字节 MTU 和软件协议校验和。 目的地址过滤允许本站单播、广播和所有多播,以支持 IPv6 邻居发现。" +msgstr "" +"ドライバーは VMXNET3 revision 1 と UPT 1 " +"を選択し、送信キューと受信キューを各一つ使用します。チェックサム、セグメンテーション、VLAN 除去、RSS、LRO " +"などのハードウェアオフロードは有効にしません。インターフェースは 1500 バイトの MTU " +"とソフトウェアによるプロトコルチェックサムを使用します。宛先アドレスフィルターは IPv6 " +"の近隣探索のため、自局ユニキャスト、ブロードキャスト、すべてのマルチキャストを許可します。" + +msgid "中断与收发调度" +msgstr "割り込みと送受信のスケジューリング" + +msgid "" +"驱动查询设备的中断偏好,优先使用一个 MSI-X 表项,其次使用 MSI;设备 明确要求 MSI 时直接尝试 " +"MSI。不支持消息中断、分配失败或设备要求 INTx 时保留轮询回退,并保持设备中断屏蔽,不猜测共享 INTx 路由。消息中断 路由到 " +"BSP,发送、接收和控制事件共用一个向量。MSI 与 MSI-X 共用 16 个向量,每个向量在一次启动内不复用;耗尽时新设备回退到轮询。" +msgstr "" +"ドライバーはデバイスの割り込み設定を問い合わせ、MSI-X エントリーを一つ試し、次に MSI を試します。MSI が明示された場合は MSI-X" +" を試しません。メッセージ割り込みを使用できない場合、割り当てに失敗した場合、または INTx が指定された場合は、共有 INTx " +"経路を推測せず、デバイス割り込みをマスクしてポーリングに切り替えます。送信、受信、制御イベントは BSP 宛ての一つのベクターを共有します。MSI" +" と MSI-X は 16 個のベクターを共有し、各ベクターは起動中に再利用されません。枯渇すると新しいデバイスはポーリングに切り替わります。" + +msgid "" +"IRQ 回调仅屏蔽设备中断、刷新 posted write 并通知核心,不解析协议包。 核心以不复用的 ifindex " +"合并通知,不在排队期间保存模块回调或设备指针。 任务上下文每轮最多检查 32 个接收描述符,每张网卡连续最多检查 8 个, " +"满预算时重新排队;空队列才重新打开中断,并在打开后复查代际位,避免 丢失检查空队列期间到达的数据。原有协议维护心跳和同步轮询路径继续保留。" +msgstr "" +"IRQ コールバックはデバイス割り込みのマスク、posted write " +"のフラッシュ、コアへの通知だけを行い、パケットを解析しません。コアは再利用しない ifindex " +"ごとに通知を集約し、待機中にモジュールのコールバックやデバイスポインターを保持しません。タスクコンテキストでは一回に最大 32 個、同じ NIC " +"について連続で最大 8 " +"個の受信記述子を確認し、予算を使い切ると再度キューに登録します。キューが空の場合にだけ割り込みを再度有効にし、その後に世代ビットを再確認して、空確認中に到着したパケットの通知を失わないようにします。従来のプロトコル保守用ハートビートと同期ポーリングも維持します。" + +msgid "" +"任务上下文消费并确认设备事件,包括 carrier 变化和队列错误。通知路径 不以旧 carrier " +"状态阻挡设备回调,否则链路恢复事件本身无法被处理。 行政关闭的接口仍排空和重新启用中断,但不把收到的数据投递到协议层。 中断模式使用事件更新的 " +"carrier 缓存,轮询模式继续查询设备;接收服务 也回收发送完成。补充接收描述符时,仅在设备设置 ``updateRxProd`` 时 写 " +"producer doorbell,减少每个包的 MMIO;初次投递仍显式通知设备。" +msgstr "" +"タスクコンテキストでキャリア変更やキュー障害を含むデバイスイベントを処理し、確認応答します。リンク復帰イベント自体を処理する必要があるため、古いキャリア状態でコールバックを阻止しません。管理上無効にしたインターフェースでも割り込みを排出して再度有効にしますが、受信パケットをプロトコル層へ渡しません。割り込みモードではイベントで更新するキャリアキャッシュを使い、ポーリングモードではデバイスへの問い合わせを続けます。受信サービスは送信完了も回収します。受信記述子を補充する際は、デバイスが" +" ``updateRxProd`` を設定した場合だけ producer doorbell に書き込み、パケットごとの MMIO " +"を減らします。初回の投入では明示的に通知します。" + +msgid "资源与错误处理" +msgstr "リソースとエラー処理" + +msgid "" +"每次回调均保留实际设备 owner。设备停止时先关闭接入、屏蔽并排空 IRQ, 再同步 quiesce 和 reset,关闭 PCI bus " +"master 并回读; 未能证明停止时保留 DMA/MMIO 和模块所有权,以便管理器重试,而不 释放仍可能被访问的内存。设备命令是同步 MMIO" +" 操作,队列满时发送 返回 ``EAGAIN``,不会无限等待硬件进度。" +msgstr "" +"各コールバックは実際のデバイス owner を固定します。停止時はまずコールバックの受け入れを止め、割り込みをマスクして IRQ " +"コールバックの終了を待ちます。続いて同期的に quiesce と reset を実行し、PCI " +"バスマスターを無効にして読み戻します。停止を確認できない場合、まだアクセスされる可能性のあるメモリーを解放せず、管理側が再試行できるよう " +"DMA/MMIO とモジュールの所有権を保持します。デバイスコマンドは同期 MMIO " +"です。送信キューが満杯の場合、ハードウェアの進行を無期限に待たず ``EAGAIN`` を返します。" + +msgid "验证" +msgstr "検証" + +msgid "" +"``tools/test_vmxnet3.py`` 编译真实驱动主体并模拟 PCI、MMIO 与 DMA " +"边界,覆盖版本协商、链路、收发环回绕、错误完成、资源回滚、失败 STOP 保留和多设备隔离,以及 MSI-X/MSI/轮询选择、中断重新打开竞态、" +" carrier 事件和 producer doorbell 条件。``tools/test_pci_msix.py`` 检查 MSI-X 表与 " +"PBA 的 BAR 边界、重叠、映射失败、表项屏蔽和旧向量隔离; ``tools/test_net_rx_budget.py`` " +"检查描述符预算与网卡之间的公平调度。" +msgstr "" +"``tools/test_vmxnet3.py`` は実際のドライバーをコンパイルし、PCI、MMIO、DMA " +"の境界を模擬します。交渉、キャリア、リングの周回、不正な完了、リソースのロールバック、STOP " +"失敗時の保持、デバイス間の分離、MSI-X/MSI/ポーリングの選択、割り込み再有効化の競合、キャリアイベント、producer doorbell" +" の条件を確認します。``tools/test_pci_msix.py`` は MSI-X テーブルと PBA の BAR " +"境界、重複、マッピング失敗、エントリーのマスク、使用済みベクターの分離を確認し、``tools/test_net_rx_budget.py`` " +"は記述子の処理予算と NIC 間の公平性を確認します。" + +msgid "" +"ReliefOS 的 ``tools/test_vmxnet3_qemu.py`` 使用两张 VMXNET3 和一张 e1000e,验证 " +"DHCP、IPv4/IPv6、并发 TCP/UDP、真实 MSI-X 计数及模块 " +"卸载、重载。``tools/tests/vmxnet3_perf_guest.c`` 通过标准 socket 验证 全部 TCP 回显字节和 " +"UDP 数据,供父仓性能编排比较耗时、CPU 统计和 往返延迟。吞吐按单方向的回显有效载荷计算,不是双向加总或网卡线速。" +msgstr "" +"ReliefOS の ``tools/test_vmxnet3_qemu.py`` は VMXNET3 2 台と e1000e 1 " +"台を使用して、DHCP、IPv4/IPv6、並行 TCP/UDP 通信、実際の MSI-X " +"回数、モジュールのアンロードと再ロードを確認します。``tools/tests/vmxnet3_perf_guest.c`` は標準 socket" +" で TCP 回送の全バイトと UDP データを検証し、親リポジトリーの性能テストで経過時間、CPU " +"統計、往復遅延を比較します。スループットは一方向の回送ペイロードであり、双方向の合計や NIC の回線速度ではありません。" + +msgid "" +"QEMU 性能、VMware 基础联网、模块生命周期和长时间负载须分别记录, 不能互相代替。宿主模型和 QEMU 不能代替 VMware " +"实际环境验证; 物理硬件也未验证。此内部驱动与调度接口不扩展 Linux/POSIX 用户态 ABI。" +msgstr "" +"QEMU での性能、VMware の基本通信、モジュールのライフサイクル、長時間負荷の検証はそれぞれ記録し、相互に代用しません。ホストモデルと " +"QEMU は実際の VMware " +"環境の代わりにはならず、物理ハードウェアも未検証です。これらの内部ドライバーとスケジューリングのインターフェースは Linux/POSIX " +"ユーザー空間 ABI を拡張しません。" diff --git a/arch/x86_64/platform/pci.c b/arch/x86_64/platform/pci.c index aa4c7228..76a66959 100644 --- a/arch/x86_64/platform/pci.c +++ b/arch/x86_64/platform/pci.c @@ -569,6 +569,18 @@ void *pci_map_mmio(uint64_t phys, uint64_t bytes) return pci_map_mmio_lease(phys,bytes); } +/** @brief Validate and map pages from the selected quiesced function's BAR. + * @param device Exact PCI identity. @param bar Low-dword memory BAR index. + * @param phys Aligned physical start. @param bytes Whole-page extent. + * @return Owned UC/RW/NX mapping or NULL; caller holds execution ownership. + */ +void *pci_map_device_bar(const struct pci_device *device, uint8_t bar, + uint64_t phys, uint64_t bytes) +{ + if (!pci_device_bar_contains(device,bar,phys,bytes)) return NULL; + return pci_map_mmio_lease(phys,bytes); +} + /** @brief Read firmware's assigned BAR0 identity without writes or sizing probes. * Only capability-header reads are admitted before handoff. A normal memory * BAR implements at least16 bytes; the containing page is a mapping granule, diff --git a/arch/x86_64/platform/pci_irq.c b/arch/x86_64/platform/pci_irq.c index 35e8dd1e..0096ad5d 100644 --- a/arch/x86_64/platform/pci_irq.c +++ b/arch/x86_64/platform/pci_irq.c @@ -9,15 +9,19 @@ struct pci_irq_entry { uint8_t capability, live, retiring, retired; void (*handler)(void *); void *opaque; + void *msix_mapping; + volatile uint32_t *msix_table; + uint64_t msix_bytes; }; static struct pci_irq_entry pci_irqs[IRQ_COUNT]; static uint32_t irq_generation; static struct kernel_spinlock pci_irq_lock = KERNEL_SPINLOCK_INIT; -/** @brief Find MSI with bounded, cycle-checked capability traversal. +/** @brief Find MSI or MSI-X with bounded, cycle-checked capability traversal. * @param d Borrowed PCI identity; config access itself is serialized. - * @return MSI offset, or 0. Task context; no callback or allocation. + * @param type MSI (5) or MSI-X (0x11) capability ID. + * @return Complete capability offset, or 0. Task context; no allocation. */ -static uint8_t find_msi(const struct reliefos_driver_pci_device *d) +static uint8_t find_capability(const struct reliefos_driver_pci_device *d, uint8_t type) { if (!(pci_config_read16(d->bus,d->slot,d->function,6) & 0x10)) return 0; uint8_t p = pci_config_read32(d->bus,d->slot,d->function,0x34) & 0xff; @@ -28,9 +32,12 @@ static uint8_t find_msi(const struct reliefos_driver_pci_device *d) if (visited & bit) return 0; visited |= bit; uint32_t cap = pci_config_read32(d->bus,d->slot,d->function,p); - if ((cap & 0xff) == 5) { - uint32_t bytes = (cap & (1u << 23)) ? 14 : 10; - if (cap & (1u << 24)) bytes = (cap & (1u << 23)) ? 24 : 20; + if ((cap & 0xff) == type) { + uint32_t bytes = 12; + if (type == 5) { + bytes = (cap & (1u << 23)) ? 14 : 10; + if (cap & (1u << 24)) bytes = (cap & (1u << 23)) ? 24 : 20; + } return p + bytes <= 256 ? p : 0; } p = (cap >> 8) & 0xff; @@ -39,7 +46,7 @@ static uint8_t find_msi(const struct reliefos_driver_pci_device *d) } /** @brief Allocate one MSI vector routed to the BSP; no speculative INTx. * @param dev Borrowed PCI function, quiesced by driver before registration. - * @param handler Nonblocking callback that reads/clears device W1C before EOI. + * @param handler Nonblocking callback that masks/acknowledges its source before EOI. * @param opaque Borrowed callback context; pinned until free returns. * @param out_handle Receives generation-tagged owned handle on success. * @return 0, -EINVAL, -ENOSPC or -ENOTSUP. Task context; no sleeping lock. @@ -51,7 +58,7 @@ int pci_request_irq(const struct reliefos_driver_pci_device *dev, void (*handler { if (!dev || !handler || !out_handle) return -22; if (!apic_enabled() || apic_bsp_id() > 255) return -95; - uint8_t capability = find_msi(dev); + uint8_t capability = find_capability(dev, 5); if (!capability) return -95; uint64_t flags; kernel_spin_lock_irqsave(&pci_irq_lock, &flags); @@ -69,6 +76,12 @@ int pci_request_irq(const struct reliefos_driver_pci_device *dev, void (*handler *e = (struct pci_irq_entry){.dev = *dev, .handle = (++irq_generation << 8) | slot, .capability = capability, .live = 1, .handler = handler, .opaque = opaque}; uint16_t control = pci_config_read16(dev->bus,dev->slot,dev->function,capability + 2); + uint8_t msix=find_capability(dev,0x11); + if (msix) { + uint16_t c=pci_config_read16(dev->bus,dev->slot,dev->function,msix+2); + pci_config_write16(dev->bus,dev->slot,dev->function,msix+2,(c&~0x8000u)|0x4000u); + (void)pci_config_read16(dev->bus,dev->slot,dev->function,msix+2); + } /* Program exactly one message, preserving MMC and read-only capability bits. */ control &= ~(1u | (7u << 4)); pci_config_write16(dev->bus,dev->slot,dev->function,capability + 2,control); @@ -86,9 +99,127 @@ int pci_request_irq(const struct reliefos_driver_pci_device *dev, void (*handler kernel_spin_unlock_irqrestore(&pci_irq_lock, flags); return 0; } -/** @brief Invoke the real MSI callback with an in-flight execution pin. + +/** @brief Validate the complete MSI-X structure against its exact memory BAR. + * @param dev Quiesced function identity. @param location BIR/offset field. + * @param bytes Actual table/PBA size. @param out Receives the physical start. + * @return True for a non-overflowing structure whose covering pages fit the BAR. + * Task context under execution ownership; sizing temporarily disables decode. + */ +static bool msix_range(const struct reliefos_driver_pci_device *dev, uint32_t location, + uint64_t bytes, uint64_t *out) +{ + uint8_t bar = location & 7u; + if (bar >= 6) return false; + uint8_t offset = 0x10 + bar * 4; + uint32_t low = pci_config_read32(dev->bus,dev->slot,dev->function,offset); + if (!low || low == UINT32_MAX || (low & 1u) || ((low & 6u) != 0 && (low & 6u) != 4)) + return false; + bool wide = (low & 6u) == 4; + if (wide && bar == 5) return false; + uint32_t high = wide ? pci_config_read32(dev->bus,dev->slot,dev->function,offset+4) : 0; + uint64_t base = ((uint64_t)high << 32) | (low & ~15u), start = location & ~7u; + if (base > UINT64_MAX - start) return false; + start += base; + if (!bytes || start > UINT64_MAX - bytes || start + bytes > UINT64_MAX - 4095u) + return false; + uint64_t page = start & ~4095ull, end = (start + bytes + 4095u) & ~4095ull; + struct pci_device identity = {.bus=dev->bus, .slot=dev->slot, .function=dev->function, + .vendor_id=dev->vendor_id, .device_id=dev->device_id}; + if (!pci_device_bar_contains(&identity,bar,page,end-page)) return false; + *out = start; + return true; +} + +/** @brief Allocate MSI-X table entry zero with every other entry masked. + * @param dev Quiesced function with exclusive driver ownership. + * @param handler IRQ-safe callback; mask/ack the device before returning. + * @param opaque Context retained until pci_free_irq returns. + * @param out_handle Receives an owned generation token only on success. + * @return Zero or negative EINVAL/ENOTSUP/EBUSY/ENOSPC/ENOMEM. + * Task context; mapping is outside the IRQ lock. No INTx fallback or table + * offset from an unvalidated BAR is used. A failed prepare enables no vector. + */ +int pci_request_msix_irq(const struct reliefos_driver_pci_device *dev, + void (*handler)(void *), void *opaque, uint32_t *out_handle) +{ + if (!dev || !handler || !out_handle) return -22; + if (!apic_enabled() || apic_bsp_id() > 255) return -95; + uint8_t capability = find_capability(dev, 0x11); + if (!capability) return -95; + uint64_t flags; + kernel_spin_lock_irqsave(&pci_irq_lock,&flags); + uint32_t slot; + for (slot=0; slotlive || e->retiring) && e->dev.bus==dev->bus && + e->dev.slot==dev->slot && e->dev.function==dev->function) { + kernel_spin_unlock_irqrestore(&pci_irq_lock,flags); return -16; + } + } + for (slot=0; slotbus,dev->slot,dev->function,capability+2); + uint32_t entries=(control&0x7ffu)+1; + uint64_t table_bytes=(uint64_t)entries*16, pba_bytes=((entries+63u)/64u)*8u; + uint32_t table_location=pci_config_read32(dev->bus,dev->slot,dev->function,capability+4); + uint32_t pba_location=pci_config_read32(dev->bus,dev->slot,dev->function,capability+8); + uint64_t table_start, pba_start; + int result=-22; + if (!msix_range(dev,table_location,table_bytes,&table_start) || + !msix_range(dev,pba_location,pba_bytes,&pba_start) || + (table_start < pba_start+pba_bytes && pba_start < table_start+table_bytes)) + goto failed; + uint64_t page=table_start&~4095ull; + e->msix_bytes=((table_start+table_bytes+4095u)&~4095ull)-page; + struct pci_device identity={.bus=dev->bus,.slot=dev->slot,.function=dev->function, + .vendor_id=dev->vendor_id,.device_id=dev->device_id}; + e->msix_mapping=pci_map_device_bar(&identity,table_location&7u,page,e->msix_bytes); + if (!e->msix_mapping) { result=-12; goto failed; } + e->msix_table=(volatile uint32_t *)((uint8_t *)e->msix_mapping+(table_start-page)); + pci_config_write16(dev->bus,dev->slot,dev->function,capability+2,(control&~0x8000u)|0x4000u); + (void)pci_config_read16(dev->bus,dev->slot,dev->function,capability+2); + for (uint32_t i=0;imsix_table[i*4+3] |= 1u; + e->msix_table[0]=0xfee00000u | ((uint32_t)apic_bsp_id()<<12); + e->msix_table[1]=0; + e->msix_table[2]=0x50+slot; + __atomic_thread_fence(__ATOMIC_SEQ_CST); + (void)e->msix_table[3]; /* Flush posted table programming before enable. */ + uint8_t msi=find_capability(dev,5); + if (msi) { + uint16_t c=pci_config_read16(dev->bus,dev->slot,dev->function,msi+2); + pci_config_write16(dev->bus,dev->slot,dev->function,msi+2,c&~1u); + } + kernel_spin_lock_irqsave(&pci_irq_lock,&flags); + e->live=1; e->retiring=0; + e->msix_table[3] &= ~1u; + (void)e->msix_table[3]; + pci_config_write16(dev->bus,dev->slot,dev->function,capability+2,(control&~0x4000u)|0x8000u); + (void)pci_config_read16(dev->bus,dev->slot,dev->function,capability+2); + *out_handle=e->handle; + kernel_spin_unlock_irqrestore(&pci_irq_lock,flags); + kernel_execution_unlock_irqrestore(execution_flags); + return 0; +failed: + kernel_execution_unlock_irqrestore(execution_flags); + kernel_spin_lock_irqsave(&pci_irq_lock,&flags); + *e=(struct pci_irq_entry){0}; + kernel_spin_unlock_irqrestore(&pci_irq_lock,flags); + return result; +} +/** @brief Invoke the MSI/MSI-X callback with an in-flight execution pin. * @param vector Hardware vector in 0x50..0x5f. - * @return None. IRQ context; callback must acknowledge W1C, never sleep. + * @return None. IRQ context; callback must mask/ack its source, never sleep. * Architecture sends EOI only after this returns. Removal waits for the pin. */ void pci_irq_dispatch(uint32_t vector) @@ -107,10 +238,11 @@ void pci_irq_dispatch(uint32_t vector) __atomic_sub_fetch(&e->active,1,__ATOMIC_RELEASE); kernel_spin_unlock_irqrestore(&pci_irq_lock, flags); } -/** @brief Disable MSI, drain ISR pins and retire the vector until reboot. +/** @brief Disable MSI/MSI-X, drain ISR pins, unmap the table and retire the vector. * @param handle Owned generation token; stale/duplicate frees are harmless. * @return None. Task context only, no execution lock and never from handler. - * Caller first stops device DMA and keeps callback memory alive until return. + * Caller first masks the device source and keeps callback memory alive until + * return. DMA quiescence must be established before freeing DMA resources. * A message pending before disable may reach dispatch after this returns; * its vector must remain a tombstone rather than identify a new callback. */ @@ -124,12 +256,25 @@ void pci_free_irq(uint32_t handle) if (!e->live || e->handle != handle) { kernel_spin_unlock_irqrestore(&pci_irq_lock, flags); return; } struct reliefos_driver_pci_device *d = &e->dev; uint16_t control = pci_config_read16(d->bus,d->slot,d->function,e->capability + 2); - pci_config_write16(d->bus,d->slot,d->function,e->capability + 2,control & ~1u); + if (e->msix_mapping) { + pci_config_write16(d->bus,d->slot,d->function,e->capability+2,(control&~0x8000u)|0x4000u); + e->msix_table[3] |= 1u; + (void)e->msix_table[3]; + } else { + pci_config_write16(d->bus,d->slot,d->function,e->capability + 2,control & ~1u); + } (void)pci_config_read16(d->bus,d->slot,d->function,e->capability + 2); e->live = 0; e->retiring = 1; kernel_spin_unlock_irqrestore(&pci_irq_lock, flags); while (__atomic_load_n(&e->active, __ATOMIC_ACQUIRE)) __asm__ volatile("pause" ::: "memory"); + if (e->msix_mapping) { + uint64_t execution_flags; + kernel_execution_lock_irqsave(&execution_flags); + pci_unmap_mmio(e->msix_mapping,e->msix_bytes); + kernel_execution_unlock_irqrestore(execution_flags); + } kernel_spin_lock_irqsave(&pci_irq_lock, &flags); e->handler = NULL; e->opaque = NULL; e->retired = 1; e->retiring = 0; + e->msix_mapping=NULL; e->msix_table=NULL; e->msix_bytes=0; kernel_spin_unlock_irqrestore(&pci_irq_lock, flags); } diff --git a/drivers/net/vmxnet3/Kbuild b/drivers/net/vmxnet3/Kbuild index 60e6bbd9..f1e6a4f0 100644 --- a/drivers/net/vmxnet3/Kbuild +++ b/drivers/net/vmxnet3/Kbuild @@ -1,5 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 obj-$(CONFIG_VMXNET3) += vmxnet3.o -vmxnet3-y := main.o hardware.o rings.o io.o module.o +vmxnet3-y := main.o hardware.o rings.o interrupt.o io.o module.o include $(srctree)/scripts/Makefile.module diff --git a/drivers/net/vmxnet3/hardware.c b/drivers/net/vmxnet3/hardware.c index 9536cdff..9fda72c1 100644 --- a/drivers/net/vmxnet3/hardware.c +++ b/drivers/net/vmxnet3/hardware.c @@ -4,7 +4,7 @@ /** @brief Issue a synchronous VMXNET3 command and read its completion. * @param d Mapped device. @param command Command word. @return Device's completion word. */ -static uint32_t command(struct vmx_device *d, uint32_t command) +uint32_t vmx_command(struct vmx_device *d, uint32_t command) { uint64_t flags; kernel_spin_lock_irqsave(&d->command_lock, &flags); @@ -37,7 +37,7 @@ int vmx_hardware_start(struct vmx_device *d) vmx_io_write(d->bar[0], VMX_IMR, 1); /* Until quiesced, the function may retain a previous owner's DMA state. */ d->exposed = true; - if (command(d, VMX_QUIESCE) || command(d, VMX_RESET)) + if (vmx_command(d, VMX_QUIESCE) || vmx_command(d, VMX_RESET)) return -5; d->exposed = false; uint32_t revision = vmx_io_read(d->bar[1], VMX_REVISION); @@ -64,14 +64,13 @@ int vmx_hardware_start(struct vmx_device *d) */ int vmx_hardware_stop(struct vmx_device *d) { - d->active = false; - if (d->bar[0]) - vmx_io_write(d->bar[0], VMX_IMR, 1); + __atomic_store_n(&d->active,false,__ATOMIC_RELEASE); + vmx_interrupt_stop(d); int failed = 0; if (d->exposed && d->bar[1]) { - if (command(d, VMX_QUIESCE)) + if (vmx_command(d, VMX_QUIESCE)) failed = 1; - if (!failed && command(d, VMX_RESET)) + if (!failed && vmx_command(d, VMX_RESET)) failed = 1; } if (d->command_saved) { @@ -87,13 +86,29 @@ int vmx_hardware_stop(struct vmx_device *d) return 0; } -/** @brief Query carrier without racing other command-register users. +/** @brief Read IRQ-cached carrier, or query the device in polling fallback. * @param d Device retained by an admitted callback. @return Nonzero if link is up. + * Task context under network execution; IRQ events may refresh the cache. */ int vmx_link(struct vmx_device *d) { if (!d->active || __atomic_load_n(&d->broken, __ATOMIC_RELAXED)) return 0; - uint32_t link = command(d, VMX_GET_LINK); - return link != UINT32_MAX && (link & 1u) != 0; + if (d->irq_handle) { + if (vmx_interrupt_events(d)) return 0; + if (!d->link_valid) vmx_refresh_link(d); + } else { + vmx_refresh_link(d); + } + return d->link_up; +} + +/** @brief Refresh task-owned carrier state with one serialized device query. + * @param d Active device retained through the calling driver callback. + */ +void vmx_refresh_link(struct vmx_device *d) +{ + uint32_t link=vmx_command(d,VMX_GET_LINK); + d->link_up=link!=UINT32_MAX && (link&1u)!=0; + d->link_valid=true; } diff --git a/drivers/net/vmxnet3/internal.h b/drivers/net/vmxnet3/internal.h index c87fe50f..3f25c678 100644 --- a/drivers/net/vmxnet3/internal.h +++ b/drivers/net/vmxnet3/internal.h @@ -27,6 +27,7 @@ #define VMX_COMMAND 0x20u #define VMX_MAC_LOW 0x28u #define VMX_MAC_HIGH 0x30u +#define VMX_EVENT_CAUSE 0x40u #define VMX_IMR 0u #define VMX_TX_PROD 0x600u #define VMX_RX_PROD 0x800u @@ -36,6 +37,7 @@ #define VMX_RESET 0xcafe0002u #define VMX_UPDATE_RX_MODE 0xcafe0003u #define VMX_GET_LINK 0xf00d0002u +#define VMX_GET_INTR_CONFIG 0xf00d0008u #define VMX_GEN 0x80000000u /* Four dwords provide the hardware's 16-byte ring cell without C bitfields. */ @@ -54,13 +56,16 @@ struct vmx_device { uint16_t original_command; bool command_saved, exposed, active; unsigned broken; + uint32_t ifindex, irq_handle, event_pending; + unsigned irq_mode; + bool link_valid, link_up, auto_mask, irq_masked; uint8_t mac[6]; uint64_t shared_pa, rings_pa, tx_data_pa, rx_data_pa; uint8_t *shared, *tx_data, *rx_data; volatile struct vmx_desc *tx, *txc, *rx, *rxc; unsigned tx_next, tx_clean, txc_next, tx_gen, txc_gen; unsigned rx_next, rx_fill, rxc_next, rx_gen, rxc_gen; - struct kernel_spinlock command_lock, tx_lock, rx_lock; + struct kernel_spinlock command_lock, tx_lock, rx_lock, irq_lock; }; /** @brief Read a 32-bit device register from one retained MMIO lease. @@ -81,10 +86,40 @@ int vmx_hardware_start(struct vmx_device *d); * resources. */ int vmx_hardware_stop(struct vmx_device *d); -/** @brief Read the carrier using the serialized command register. - * @param d Live context. @return Nonzero only while the device reports link up. +/** @brief Read cached carrier in IRQ mode or query it in polling fallback. + * @param d Live callback-pinned context under network execution. + * @return Nonzero only while the device reports link up; task context only. */ int vmx_link(struct vmx_device *d); +/** @brief Issue a command under the per-device command lock. + * @param d Mapped retained controller. @param value Command word. + * @return Synchronous completion word; task context, no sleeping. + */ +uint32_t vmx_command(struct vmx_device *d, uint32_t value); +/** @brief Refresh the task-context carrier cache after activation or a link event. + * @param d Active retained controller. Command access is serialized. + */ +void vmx_refresh_link(struct vmx_device *d); +/** @brief Prefer one owned MSI-X entry, then MSI, otherwise retain polling. + * @param d Quiesced controller whose BARs are mapped; init task context. + */ +void vmx_interrupt_prepare(struct vmx_device *d); +/** @brief Mask the device and synchronously drain the owned IRQ callback. + * @param d Retained controller with callback admission closed; task context. + */ +void vmx_interrupt_stop(struct vmx_device *d); +/** @brief Consume event causes in task context and refresh cached carrier. + * @param d Retained active controller. @return Zero or negative EIO. + */ +int vmx_interrupt_events(struct vmx_device *d); +/** @brief Rearm only after empty RX/TX service and recheck for a racing completion. + * @param d Active retained controller; caller holds rx_lock. Task context only. + */ +void vmx_interrupt_complete(struct vmx_device *d); +/** @brief Reclaim validated TX completions under the queue lock. + * @param d Retained active controller. @return Zero or negative EIO. + */ +int vmx_reclaim_tx(struct vmx_device *d); /** @brief Allocate and initialize coherent shared memory and descriptor rings. * @param d Negotiated device. @return Zero or -ENOMEM, retaining partial leases for cleanup. */ diff --git a/drivers/net/vmxnet3/interrupt.c b/drivers/net/vmxnet3/interrupt.c new file mode 100644 index 00000000..a70836cc --- /dev/null +++ b/drivers/net/vmxnet3/interrupt.c @@ -0,0 +1,111 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +#include "internal.h" +#include +#include + +/** @brief Mask one message source and coalesce task work without parsing packets. + * @param context IRQ-pinned device; no allocation or protocol callback is allowed. + */ +static void interrupt(void *context) +{ + struct vmx_device *d=context; + uint64_t flags; + kernel_spin_lock_irqsave(&d->irq_lock,&flags); + vmx_io_write(d->bar[0],VMX_IMR,1); + (void)vmx_io_read(d->bar[0],VMX_IMR); + d->irq_masked=true; + __atomic_store_n(&d->event_pending,1,__ATOMIC_RELEASE); + bool notify=__atomic_load_n(&d->active,__ATOMIC_ACQUIRE) && d->ifindex; + kernel_spin_unlock_irqrestore(&d->irq_lock,flags); + if (notify) netdev_rx_notify(d->ifindex); +} + +/** @brief Negotiate a single MSI-X/MSI message, preserving a poll-only fallback. + * @param d Quiesced device with complete BAR mappings. Init task context only. + */ +void vmx_interrupt_prepare(struct vmx_device *d) +{ + d->irq_masked=true; + if (!d->api->free_pci_irq) return; + uint32_t config=vmx_command(d,VMX_GET_INTR_CONFIG), type=config&3u; + d->auto_mask=((config>>2)&3u)!=1u; + if (config==UINT32_MAX || type==1u) return; /* No speculative shared INTx. */ + int result=-95; + if (type!=2u) { + result=driver_request_pci_msix_irq(&d->pci,interrupt,d,&d->irq_handle); + if (!result) d->irq_mode=1; + } + if (result && d->api->request_pci_irq) { + result=d->api->request_pci_irq(&d->pci,interrupt,d,&d->irq_handle); + if (!result) d->irq_mode=2; + } + if (result) d->irq_handle=0; +} + +/** @brief Stop message production and wait for all retained IRQ callbacks. + * @param d Context with network callback admission drained, or partial init. + * Task context; no spinlock spans the provider's callback synchronization. + */ +void vmx_interrupt_stop(struct vmx_device *d) +{ + uint64_t flags; + kernel_spin_lock_irqsave(&d->irq_lock,&flags); + if (d->bar[0]) { + vmx_io_write(d->bar[0],VMX_IMR,1); + (void)vmx_io_read(d->bar[0],VMX_IMR); + } + uint32_t handle=d->irq_handle; + d->irq_handle=0; + d->irq_masked=true; + kernel_spin_unlock_irqrestore(&d->irq_lock,flags); + if (handle) d->api->free_pci_irq(handle); +} + +/** @brief Acknowledge events in task context, updating carrier or closing bad queues. + * @param d Active, callback-pinned device. @return Zero or negative EIO. + * A new IRQ may set a successor hint while this one is consumed. Queue errors + * remain masked and stop data admission instead of reusing untrusted buffers. + */ +int vmx_interrupt_events(struct vmx_device *d) +{ + if (d->irq_handle && __atomic_exchange_n(&d->event_pending,0,__ATOMIC_ACQ_REL)) { + uint32_t events=vmx_io_read(d->bar[1],VMX_EVENT_CAUSE); + if (events && events!=UINT32_MAX) { + vmx_io_write(d->bar[1],VMX_EVENT_CAUSE,events); + if (events&4u) vmx_refresh_link(d); + } + if (events==UINT32_MAX || (events&0x0bu)) { + __atomic_store_n(&d->broken,1,__ATOMIC_RELAXED); + d->api->console_log(CONSOLE_LOG_WARN,"[vmxnet3] %02x:%02x.%u queue/device event=%08x; queues stopped\n", + d->pci.bus,d->pci.slot,d->pci.function,events); + } + } + return __atomic_load_n(&d->broken,__ATOMIC_RELAXED) ? -5 : 0; +} + +/** @brief Rearm an empty queue, then close the empty-check/unmask race. + * @param d Active retained device; caller holds rx_lock and has serviced TX. + * IRQ lock serializes IMR writes with ISR masking. Coherent generation reads + * after the posted unmask ensure a raced completion receives another turn. + */ +void vmx_interrupt_complete(struct vmx_device *d) +{ + if (!d->irq_handle || __atomic_load_n(&d->broken,__ATOMIC_RELAXED)) return; + uint64_t flags; + kernel_spin_lock_irqsave(&d->irq_lock,&flags); + bool pending=false; + if (d->active && d->irq_masked) { + vmx_io_write(d->bar[0],VMX_IMR,0); + (void)vmx_io_read(d->bar[0],VMX_IMR); + d->irq_masked=false; + __atomic_thread_fence(__ATOMIC_SEQ_CST); + pending=(d->rxc[d->rxc_next].b>>31)==d->rxc_gen; + if (pending) { + vmx_io_write(d->bar[0],VMX_IMR,1); + (void)vmx_io_read(d->bar[0],VMX_IMR); + d->irq_masked=true; + } + } + kernel_spin_unlock_irqrestore(&d->irq_lock,flags); + if (pending) netdev_rx_notify(d->ifindex); +} diff --git a/drivers/net/vmxnet3/main.c b/drivers/net/vmxnet3/main.c index 2dc6f0a8..d4eec7de 100644 --- a/drivers/net/vmxnet3/main.c +++ b/drivers/net/vmxnet3/main.c @@ -101,14 +101,20 @@ static int start(const struct reliefos_driver_kernel_api *api) *d = (struct vmx_device){.api = api, .pci = pci, .next = devices}; devices = d; rc = vmx_hardware_start(d); + if (!rc) + vmx_interrupt_prepare(d); if (!rc) rc = vmx_allocate(d); if (!rc) rc = vmx_activate(d); if (!rc) { - d->active = true; - uint32_t ifindex; + uint32_t ifindex=0; rc = driver_register_netdev(&ops, d, &ifindex); + if (!rc) { + d->ifindex=ifindex; + __atomic_store_n(&d->active,true,__ATOMIC_RELEASE); + if (d->irq_handle) netdev_rx_notify(d->ifindex); + } } if (rc) { api->console_log(CONSOLE_LOG_WARN, "[vmxnet3] %02x:%02x.%u initialization failed: %d\n", @@ -123,9 +129,10 @@ static int start(const struct reliefos_driver_kernel_api *api) } ++registered; api->console_log(CONSOLE_LOG_INFO, - "[vmxnet3] %02x:%02x.%u MAC=%02x:%02x:%02x:%02x:%02x:%02x link=%s\n", + "[vmxnet3] %02x:%02x.%u MAC=%02x:%02x:%02x:%02x:%02x:%02x link=%s irq=%s\n", pci.bus, pci.slot, pci.function, d->mac[0], d->mac[1], d->mac[2], - d->mac[3], d->mac[4], d->mac[5], ready(d) ? "up" : "down"); + d->mac[3], d->mac[4], d->mac[5], ready(d) ? "up" : "down", + d->irq_mode==1 ? "msix" : d->irq_mode==2 ? "msi" : "poll"); } return registered ? 0 : first_error ? first_error : -19; } @@ -151,7 +158,7 @@ const struct reliefos_driver_module vmxnet3_driver_module = { .struct_size = sizeof(struct reliefos_driver_module), .kind = RELIEFOS_DRIVER_KIND_NETWORK, .name = "vmxnet3", - .version = 1, + .version = 2, .init = start, .fini = stop, }; diff --git a/drivers/net/vmxnet3/rings.c b/drivers/net/vmxnet3/rings.c index c42370f2..05060e9b 100644 --- a/drivers/net/vmxnet3/rings.c +++ b/drivers/net/vmxnet3/rings.c @@ -65,8 +65,10 @@ int vmx_activate(struct vmx_device *d) s[60] = 1; s[62] = 1; s[63] = 1; /* one fragment and one queue each */ + s[80] = d->irq_handle && d->auto_mask; s[81] = 1; - put32(s, 108, 1); /* one vector, globally masked */ + s[83] = 8; /* UPT adaptive interrupt moderation. */ + put32(s, 108, d->irq_handle ? 0 : 1); /* Poll-only fallback stays globally masked. */ put32(s, 120, 0x0d); /* unicast, broadcast and all multicast */ for (unsigned i = 0; i < 128; ++i) put32(s, 136 + i * 4, UINT32_MAX); @@ -125,22 +127,12 @@ static int broken(struct vmx_device *d) return -5; } -/** @brief Submit one packet and reclaim only validated TX completions. - * @param d Active context. @param frame Borrowed frame. @param length Frame bytes. - * @return Zero, -EINVAL, -EMSGSIZE, -ENETDOWN, -EAGAIN or -EIO. +/** @brief Reclaim ordered TX completions without waiting for device progress. + * @param d Active retained context; caller holds tx_lock with IRQs saved. + * @return Zero or negative EIO after marking a corrupt queue unusable. */ -int vmx_send(struct vmx_device *d, const void *frame, uint32_t length) +static int reclaim_tx_locked(struct vmx_device *d) { - if (!frame || !length) - return -22; - if (length > VMX_FRAME_MAX) - return -90; - if (__atomic_load_n(&d->broken, __ATOMIC_RELAXED)) - return -5; - if (!vmx_link(d)) - return -100; - uint64_t flags; - kernel_spin_lock_irqsave(&d->tx_lock, &flags); while (d->tx_clean != d->tx_next) { volatile struct vmx_desc *c = &d->txc[d->txc_next]; uint32_t last = c->b; @@ -149,9 +141,7 @@ int vmx_send(struct vmx_device *d, const void *frame, uint32_t length) __atomic_thread_fence(__ATOMIC_ACQUIRE); unsigned index = (unsigned)(c->address & 0xfffu), type = (last >> 24) & 0x7fu; if (type || index != d->tx_clean) { - int rc = broken(d); - kernel_spin_unlock_irqrestore(&d->tx_lock, flags); - return rc; + return broken(d); } d->tx_clean = (d->tx_clean + 1) % VMX_TX_COUNT; if (++d->txc_next == VMX_TX_COUNT) { @@ -159,6 +149,35 @@ int vmx_send(struct vmx_device *d, const void *frame, uint32_t length) d->txc_gen ^= 1; } } + return 0; +} + +/** @brief Reclaim TX completions even when the next workload is receive-only. + * @param d Active retained controller. @return Zero or negative EIO. + */ +int vmx_reclaim_tx(struct vmx_device *d) +{ + uint64_t flags; + kernel_spin_lock_irqsave(&d->tx_lock,&flags); + int result=reclaim_tx_locked(d); + kernel_spin_unlock_irqrestore(&d->tx_lock,flags); + return result; +} + +/** @brief Submit one frame and reclaim already completed descriptors without waiting. + * @param d Active retained device. @param frame Borrowed Ethernet bytes. + * @param length Frame bytes. @return Zero or negative Linux validation/queue errno. + */ +int vmx_send(struct vmx_device *d, const void *frame, uint32_t length) +{ + if (!frame || !length) return -22; + if (length>VMX_FRAME_MAX) return -90; + if (__atomic_load_n(&d->broken,__ATOMIC_RELAXED)) return -5; + if (!vmx_link(d)) return -100; + uint64_t flags; + kernel_spin_lock_irqsave(&d->tx_lock,&flags); + int result=reclaim_tx_locked(d); + if (result) { kernel_spin_unlock_irqrestore(&d->tx_lock,flags); return result; } unsigned index = d->tx_next, next = (index + 1) % VMX_TX_COUNT; if (next == d->tx_clean) { kernel_spin_unlock_irqrestore(&d->tx_lock, flags); @@ -195,11 +214,13 @@ int vmx_receive(struct vmx_device *d, void *frame, uint32_t capacity, uint32_t * return -5; if (!d->active) return -19; + if (vmx_interrupt_events(d) || vmx_reclaim_tx(d)) return -5; uint64_t flags; kernel_spin_lock_irqsave(&d->rx_lock, &flags); volatile struct vmx_desc *c = &d->rxc[d->rxc_next]; uint32_t last = c->b; if ((last >> 31) != d->rxc_gen) { + vmx_interrupt_complete(d); kernel_spin_unlock_irqrestore(&d->rx_lock, flags); return 0; } @@ -240,7 +261,9 @@ int vmx_receive(struct vmx_device *d, void *frame, uint32_t capacity, uint32_t * d->rxc_gen ^= 1; } __atomic_thread_fence(__ATOMIC_RELEASE); - vmx_io_write(d->bar[0], VMX_RX_PROD, d->rx_fill); + /* Device-owned updateRxProd requests doorbells only when it needs them. */ + if (*(volatile uint8_t *)(d->shared+VMX_QUEUE_OFFSET+256)) + vmx_io_write(d->bar[0], VMX_RX_PROD, d->rx_fill); kernel_spin_unlock_irqrestore(&d->rx_lock, flags); return rc; } diff --git a/include/reliefnt/deferred.h b/include/reliefnt/deferred.h index a6bd5760..b1c8b531 100644 --- a/include/reliefnt/deferred.h +++ b/include/reliefnt/deferred.h @@ -2,7 +2,8 @@ #ifndef RELIEFNT_DEFERRED_H #define RELIEFNT_DEFERRED_H #include -enum kernel_deferred_service { DEFERRED_USB, DEFERRED_VFS, DEFERRED_GRAPHICS, DEFERRED_AUDIO }; +enum kernel_deferred_service { DEFERRED_USB, DEFERRED_VFS, DEFERRED_GRAPHICS, DEFERRED_AUDIO, + DEFERRED_NET_RX }; /** @brief Coalesce a permanent dispatcher without executing provider callbacks. * @param service Bounded core service selector; invalid values are ignored. * IRQ/task safe, allocation-free. Standalone subsystem fixtures can omit the diff --git a/include/reliefnt/driver_resources.h b/include/reliefnt/driver_resources.h index 9a3cf121..55385bae 100644 --- a/include/reliefnt/driver_resources.h +++ b/include/reliefnt/driver_resources.h @@ -33,14 +33,22 @@ void driver_unmap_mmio(void *ptr,uint64_t bytes); /** @brief Register an init-owned MSI callback and its cleanup obligation. * @param owner Loading module slot; must be less than RELIEFOS_DRIVER_MAX. * @param dev Borrowed quiesced PCI function identity. - * @param handler Nonblocking W1C callback; read/clear device before returning. + * @param handler Nonblocking callback; mask/ack its source before returning. * @param opaque Borrowed module context retained until free synchronization. * @param out_handle Receives an owned generation token. * @return 0 or provider negative errno. Task context, no callback under ledger lock. */ int driver_request_pci_irq_owned(uint32_t owner,const struct reliefos_driver_pci_device *dev, void (*handler)(void *),void *opaque,uint32_t *out_handle); -/** @brief Remove an exact module IRQ lease, then disable and synchronize MSI. +/** @brief Register one init-owned MSI-X entry and its synchronized cleanup. + * @param owner Loading slot. @param dev Quiesced exclusive PCI identity. + * @param handler Nonblocking IRQ callback. @param opaque Retained context. + * @param out_handle Owned token output. @return Zero or negative errno. + * Task context; failed ledger admission disables/unmaps the prepared entry. + */ +int driver_request_pci_msix_irq_owned(uint32_t owner,const struct reliefos_driver_pci_device *dev, + void (*handler)(void *),void *opaque,uint32_t *out_handle); +/** @brief Remove an exact module IRQ lease, then disable and drain MSI/MSI-X. * @param handle Owned generation token. * @return None. Task context, never from ISR; module stays mapped through return. */ diff --git a/include/reliefnt/net.h b/include/reliefnt/net.h index e841b307..627fea6b 100644 --- a/include/reliefnt/net.h +++ b/include/reliefnt/net.h @@ -40,6 +40,12 @@ void net_tcp_maintenance(void); */ int net_get_config(struct reliefos_net_config *config); void net_poll_packets(void); +/** @brief Drain IRQ-notified NICs using bounded, fair receive slices. + * @param budget Maximum descriptor attempts, including drops and empty polls. + * Task context with network execution ownership; full queues request another + * permanent dispatcher turn instead of monopolizing an IRQ or worker stack. + */ +void net_poll_rx_budget(uint32_t budget); /** * @brief Transmit a raw IPv4 message over the configured Ethernet route. * @param destination Host-order destination address. diff --git a/include/reliefnt/net_device.h b/include/reliefnt/net_device.h index b17a98cb..55267d11 100644 --- a/include/reliefnt/net_device.h +++ b/include/reliefnt/net_device.h @@ -32,6 +32,17 @@ int driver_register_netdev(const struct reliefnt_netdev_ops *ops, void *context, * @param after Previous index, or zero. @return The next index or zero. */ uint32_t netdev_next(uint32_t after); +/** @brief Queue a coalesced task-context receive pass for one NIC. + * @param ifindex Never-reused registered identity; stale IDs are ignored. + * IRQ/task safe, no allocation or provider callback; hints received before + * publication are retained, and no module/context pointer is queued. + */ +void netdev_rx_notify(uint32_t ifindex); +/** @brief Claim a pending visible NIC using circular index order. + * @param after Previous serviced identity. @return Pending ID or zero. + * Task context under network execution; consumers revalidate with netdev_poll. + */ +uint32_t netdev_rx_take(uint32_t after); /** @brief Query carrier readiness of the exact NIC. * @param ifindex Stable NIC index. @return Nonzero only when ready. */ @@ -52,6 +63,13 @@ int netdev_send(uint32_t ifindex, const void *frame, uint32_t length); * @return One frame, zero if empty, or negative Linux errno. */ int netdev_poll(uint32_t ifindex, void *frame, uint32_t capacity, uint32_t *out_length); +/** @brief Poll an IRQ-notified NIC without rejecting a carrier-change event. + * @param ifindex Stable identity. @param frame Writable buffer. + * @param capacity Buffer bytes. @param out_length Optional output size. + * @return One, zero or negative errno. Task context under network execution; + * keeps the normal provider-owner pin even when its cached carrier is down. + */ +int netdev_poll_notified(uint32_t ifindex, void *frame, uint32_t capacity, uint32_t *out_length); /** @brief Copy an exact NIC identity, clearing the output if absent. * @param ifindex Stable NIC index. @param out Caller-owned nullable output. */ diff --git a/include/reliefnt/pci.h b/include/reliefnt/pci.h index 81063db3..c69ca42c 100644 --- a/include/reliefnt/pci.h +++ b/include/reliefnt/pci.h @@ -113,6 +113,16 @@ void pci_unmap_mmio(void *ptr, uint64_t bytes); * exact claims share a pointer. Caller drains device/users before exact unmap. */ void *pci_map_mmio(uint64_t phys, uint64_t bytes); +/** @brief Map covering pages inside one exact, quiesced device memory BAR. + * @param device Exclusive PCI function identity. @param bar Low-dword BAR index. + * @param phys Page-aligned physical start, which may be inside the BAR. + * @param bytes Nonzero page-aligned mapping length. + * @return Owned UC/RW/NX lease or NULL; release with pci_unmap_mmio. + * Task context under execution ownership. Validates identity and BAR geometry + * before mapping; never probes another function or trusts a high-dword BIR. + */ +void *pci_map_device_bar(const struct pci_device *device, uint8_t bar, + uint64_t phys, uint64_t bytes); /** @brief Map firmware's assigned BAR0 page without probing or changing decode. * @param device Exact present PCI identity retained by the caller. * @param phys Expected page-aligned memory BAR0 base, never a caller-chosen range. diff --git a/include/reliefnt/pci_irq.h b/include/reliefnt/pci_irq.h index edc542fc..e28a94db 100644 --- a/include/reliefnt/pci_irq.h +++ b/include/reliefnt/pci_irq.h @@ -3,7 +3,7 @@ #include /** @brief Allocate one MSI vector routed to the BSP; no speculative INTx. * @param dev Borrowed PCI function, quiesced by driver before registration. - * @param handler Nonblocking callback that reads/clears device W1C before EOI. + * @param handler Nonblocking callback that masks/acknowledges its source before EOI. * @param opaque Borrowed callback context; pinned until free returns. * @param out_handle Receives generation-tagged owned handle on success. * @return 0, -EINVAL, -ENOSPC or -ENOTSUP. Task context; no sleeping lock. @@ -12,16 +12,34 @@ */ int pci_request_irq(const struct reliefos_driver_pci_device *dev, void (*handler)(void *), void *opaque, uint32_t *out_handle); -/** @brief Invoke the real MSI callback with an in-flight execution pin. +/** @brief Allocate MSI-X entry zero routed to the BSP, masking unused entries. + * @param dev Exclusive quiesced function. @param handler Nonblocking IRQ callback. + * @param opaque Stable context through free. @param out_handle Owned token output. + * @return Zero or negative EINVAL/ENOTSUP/EBUSY/ENOSPC/ENOMEM. + * Task context, with bounded table/PBA validation and synchronized mappings. + * Shares MSI's never-reused vector budget. Release with pci_free_irq. + */ +int pci_request_msix_irq(const struct reliefos_driver_pci_device *dev, + void (*handler)(void *), void *opaque, uint32_t *out_handle); +/** @brief Bind MSI-X entry zero to the currently initializing driver owner. + * @param dev Exclusive quiesced function. @param handler Nonblocking IRQ callback. + * @param opaque Stable module context. @param out_handle Owned generation output. + * @return Zero or provider/ledger errno. Init task context; automatic owner + * cleanup disables messages and drains handlers before module fini/unmapping. + */ +int driver_request_pci_msix_irq(const struct reliefos_driver_pci_device *dev, + void (*handler)(void *), void *opaque, uint32_t *out_handle); +/** @brief Invoke the MSI/MSI-X callback with an in-flight execution pin. * @param vector Hardware vector in 0x50..0x5f. - * @return None. IRQ context; callback must acknowledge W1C, never sleep. + * @return None. IRQ context; callback must mask/ack its source, never sleep. * Architecture sends EOI only after this returns. Removal waits for the pin. */ void pci_irq_dispatch(uint32_t vector); -/** @brief Disable MSI, drain ISR pins and retire the vector until reboot. +/** @brief Disable MSI/MSI-X, drain ISR pins and retire the vector until reboot. * @param handle Owned generation token; stale/duplicate frees are harmless. * @return None. Task context only, no execution lock and never from handler. - * Caller first stops device DMA and keeps callback memory alive until return. + * Caller first masks the device source and keeps callback memory alive until + * return. DMA quiescence must be established before freeing DMA resources. * Pending messages can still arrive; the vector never names a new owner. */ void pci_free_irq(uint32_t handle); diff --git a/kernel/device/api.c b/kernel/device/api.c index 0a94a08d..1e789437 100644 --- a/kernel/device/api.c +++ b/kernel/device/api.c @@ -1,4 +1,6 @@ #include +#include +#include #include "manager_internal.h" @@ -112,6 +114,18 @@ int driver_request_pci_irq(const struct reliefos_driver_pci_device *dev, return driver_request_pci_irq_owned((uint32_t)loading_slot,dev,handler,opaque,out_handle); } +/** @brief Register a single MSI-X table entry with the loading driver's ledger. + * @param dev Quiesced PCI identity. @param handler Nonblocking IRQ callback. + * @param opaque Context retained until free. @param out_handle Owned token output. + * @return Zero or negative errno; init task context, never an unowned allocation. + */ +int driver_request_pci_msix_irq(const struct reliefos_driver_pci_device *dev, + void (*handler)(void *),void *opaque,uint32_t *out_handle) +{ + return driver_request_pci_msix_irq_owned((uint32_t)loading_slot,dev,handler,opaque,out_handle); +} +EXPORT_SYMBOL(driver_request_pci_msix_irq); + /** @brief Copy a v2 card contract and bind the currently loading module owner. * @param identity Borrowed identity, copied by core. * @param ops Borrowed operations, copied by core. diff --git a/kernel/device/driver_resources.c b/kernel/device/driver_resources.c index 3cccfe9c..d7900f9e 100644 --- a/kernel/device/driver_resources.c +++ b/kernel/device/driver_resources.c @@ -132,7 +132,24 @@ int driver_request_pci_irq_owned(uint32_t owner,const struct reliefos_driver_pci if(ret){pci_free_irq(handle);return ret;} *out_handle=handle;return 0; } -/** @brief Remove an exact module IRQ lease, then disable and synchronize MSI. + +/** @brief Allocate an MSI-X entry with rollback on failed owner registration. + * @param owner Loading driver slot. @param dev Quiesced exclusive PCI function. + * @param handler Nonblocking IRQ callback. @param opaque Retained driver context. + * @param out_handle Owned token output. @return Zero or provider/ledger errno. + * Task context, no ledger lock spans table mapping or callback synchronization. + */ +int driver_request_pci_msix_irq_owned(uint32_t owner,const struct reliefos_driver_pci_device *dev, + void (*handler)(void *),void *opaque,uint32_t *out_handle) +{ + if(owner>=RELIEFOS_DRIVER_MAX || !out_handle)return -22; + uint32_t handle;int ret=pci_request_msix_irq(dev,handler,opaque,&handle); + if(ret)return ret; + ret=driver_resource_add(owner,DRIVER_RESOURCE_IRQ,handle,0,0); + if(ret){pci_free_irq(handle);return ret;} + *out_handle=handle;return 0; +} +/** @brief Remove an exact module IRQ lease, then disable and drain MSI/MSI-X. * @param handle Owned generation token. * @return None. Task context, never from ISR; module stays mapped through return. */ diff --git a/kernel/device/services.c b/kernel/device/services.c index 3cfe7550..8e701ebb 100644 --- a/kernel/device/services.c +++ b/kernel/device/services.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "manager_internal.h" /** @@ -25,7 +26,7 @@ struct netdev_binding { struct reliefnt_netdev_ops ops; void *context; uint32_t owner, ifindex; - bool published; + bool published, rx_pending; uint8_t mac_cache[6]; struct net_proc_counters counters; }; @@ -442,13 +443,16 @@ EXPORT_SYMBOL(driver_register_netdev); void driver_netdev_publish_owner(uint32_t owner) { for (;;) { - uint64_t flags; uint32_t id = 0; + uint64_t flags; uint32_t id = 0; bool pending = false; kernel_spin_lock_irqsave(&manager_service_lock, &flags); for (struct netdev_binding *b=netdev_bindings; b; b=b->next) - if (b->owner == owner && !b->published) { b->published=true; id=b->ifindex; break; } + if (b->owner == owner && !b->published) { + b->published=true; id=b->ifindex; pending=b->rx_pending; break; + } kernel_spin_unlock_irqrestore(&manager_service_lock, flags); if (!id) break; net_device_attached(id); + if (pending) kernel_deferred_schedule(DEFERRED_NET_RX); } } @@ -500,6 +504,44 @@ uint32_t netdev_next(uint32_t after) return result; } +/** @brief Coalesce a receive notification without retaining any provider pointer. + * @param ifindex Never-reused device identity; stale/removed IDs are ignored. + * IRQ/task safe, allocation-free. COMING devices retain the hint until publish; + * task dispatch takes the ordinary owner pin before entering driver code. + */ +void netdev_rx_notify(uint32_t ifindex) +{ + bool visible=false; + uint64_t flags; kernel_spin_lock_irqsave(&manager_service_lock,&flags); + for (struct netdev_binding *b=netdev_bindings; b; b=b->next) + if (b->ifindex==ifindex) { b->rx_pending=true; visible=b->published; break; } + kernel_spin_unlock_irqrestore(&manager_service_lock,flags); + if (visible) kernel_deferred_schedule(DEFERRED_NET_RX); +} +EXPORT_SYMBOL(netdev_rx_notify); + +/** @brief Claim one pending published identity in round-robin index order. + * @param after Previously serviced index, or zero to start at the first NIC. + * @return Copied pending index or zero, never a context or module callback. + * Task context under network execution; registry removal can safely discard + * an unclaimed hint and netdev_poll revalidates an already claimed identity. + */ +uint32_t netdev_rx_take(uint32_t after) +{ + struct netdev_binding *first=NULL, *next=NULL; + uint64_t flags; kernel_spin_lock_irqsave(&manager_service_lock,&flags); + for (struct netdev_binding *b=netdev_bindings; b; b=b->next) { + if (!b->published || !b->rx_pending) continue; + if (!first || b->ifindexifindex) first=b; + if (b->ifindex>after && (!next || b->ifindexifindex)) next=b; + } + if (!next) next=first; + uint32_t result=0; + if (next) { next->rx_pending=false; result=next->ifindex; } + kernel_spin_unlock_irqrestore(&manager_service_lock,flags); + return result; +} + /** @brief Report the current carrier for one retained NIC. * @param ifindex Stable index. @return Nonzero when its provider reports ready. */ @@ -548,15 +590,18 @@ int netdev_send(uint32_t ifindex, const void *frame, uint32_t length) /** @brief Receive one frame and account it to its actual interface. * @param ifindex Stable index. @param frame Writable buffer. * @param capacity Buffer bytes. @param out_length Optional returned bytes. - * @return One frame, zero for empty, or a negative Linux errno. + * @param notified Bypass the carrier gate to service IRQ control/link events. + * @return One frame, zero for empty, or a negative Linux errno. Task context; + * the provider and its module remain pinned through polling and accounting. */ -int netdev_poll(uint32_t ifindex, void *frame, uint32_t capacity, uint32_t *out_length) +static int netdev_receive(uint32_t ifindex, void *frame, uint32_t capacity, + uint32_t *out_length, bool notified) { if (out_length) *out_length=0; struct netdev_binding *b=netdev_pin(ifindex); if (!b) return -19; uint32_t owner=b->owner, length=0; - if (!b->ops.is_ready(b->context)) { + if (!notified && !b->ops.is_ready(b->context)) { /* No receive descriptor was inspected while carrier is unavailable. */ driver_manager_service_unpin(owner); return -19; @@ -572,6 +617,24 @@ int netdev_poll(uint32_t ifindex, void *frame, uint32_t capacity, uint32_t *out_ driver_manager_service_unpin(owner); return ret; } +/** @brief Receive one frame while preserving legacy carrier-down behavior. + * @param ifindex Stable NIC identity. @param frame Writable receive buffer. + * @param capacity Buffer size. @param out_length Optional received byte count. + * @return One frame, zero if empty, or negative errno; task context, owner pinned. + */ +int netdev_poll(uint32_t ifindex, void *frame, uint32_t capacity, uint32_t *out_length) +{ return netdev_receive(ifindex,frame,capacity,out_length,false); } + +/** @brief Service an IRQ-notified provider even while its carrier is down. + * @param ifindex Stable NIC identity. @param frame Writable receive buffer. + * @param capacity Buffer bytes. @param out_length Optional returned frame size. + * @return One, zero or negative errno. Task context under network execution; + * the same owner pin spans control-event acknowledgement and queue processing. + * Carrier cannot gate this path: a link-up event itself may be the notification. + */ +int netdev_poll_notified(uint32_t ifindex, void *frame, uint32_t capacity, uint32_t *out_length) +{ return netdev_receive(ifindex,frame,capacity,out_length,true); } + /** @brief Copy one provider's PCI identity and carrier state while pinned. * @param ifindex Stable index. @param out Caller-owned nullable output. */ diff --git a/kernel/workqueue/services.c b/kernel/workqueue/services.c index 489f57c6..50d9bd79 100644 --- a/kernel/workqueue/services.c +++ b/kernel/workqueue/services.c @@ -50,10 +50,17 @@ static void graphics_work(struct kernel_work *work,void *context) */ static void audio_work(struct kernel_work *work,void *context) { (void)work;(void)context;driver_manager_process_audio_faults(); } +/** @brief Drain interrupt-notified NICs without running the protocol stack in IRQ. + * @param work Permanent core dispatcher. @param context Unused NULL argument. + * A full NIC slice coalesces a successor; all callbacks use netdev owner pins. + */ +static void network_rx_work(struct kernel_work *work,void *context) +{ (void)work;(void)context;net_poll_rx_budget(32); } static struct kernel_work network=KERNEL_WORK_INIT(network_work,NULL); static struct kernel_work services[]={ KERNEL_WORK_INIT(usb_work,NULL),KERNEL_WORK_INIT(vfs_work,NULL), - KERNEL_WORK_INIT(graphics_work,NULL),KERNEL_WORK_INIT(audio_work,NULL)}; + KERNEL_WORK_INIT(graphics_work,NULL),KERNEL_WORK_INIT(audio_work,NULL), + KERNEL_WORK_INIT(network_rx_work,NULL)}; /** @brief Coalesce a builtin dispatcher while preserving subsystem ownership. * @param service Valid permanent service index. IRQ/task safe, no callback. */ diff --git a/net/input.c b/net/input.c index 1a0283ed..dba93927 100644 --- a/net/input.c +++ b/net/input.c @@ -88,6 +88,42 @@ void net_poll_packets(void) for (unsigned i = 0; i < 32; ++i) net_poll_once(0, 0, 0, 0); } +/** @brief Drain notified NICs in fair slices with a strict descriptor budget. + * @param budget Maximum receive attempts, including empty/dropped descriptors. + * Task context under network execution ownership. Each slice admits ordinary + * netdev_poll owner pins; no module callback/context is retained between turns. + * A full slice requeues the NIC so only an observed empty queue completes it. + * Administratively down links still drain/rearm control events, but their + * packets never enter the protocol stack or AF_PACKET receive path. + */ +void net_poll_rx_budget(uint32_t budget) +{ + static uint32_t previous; + uint8_t frame[NET_FRAME_MAX]; + uint32_t used=0; + while (used0 || result==-90 || result==-74; + if (result>0 && length && net_interface_is_up(id)) { + net_packet_input_on(id,frame,length); + net_process_frame(id,frame,length,NULL,NULL,NULL,NULL); + } + if (!more) break; + } + if (more) netdev_rx_notify(id); + net_tcp_service_sockets(); + net_ipv6_poll(); + } +} + /** * @brief Test whether TCP or IPv6 work is due for its next maintenance batch. * @return True when active work and the current tick permit a bounded poll pass. diff --git a/tools/test_net_rx_budget.py b/tools/test_net_rx_budget.py new file mode 100644 index 00000000..3332eaf2 --- /dev/null +++ b/tools/test_net_rx_budget.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +"""Exercise task-context IRQ receive budgets using production network input.""" +from pathlib import Path +import os +import subprocess +import tempfile + +ROOT = Path(__file__).resolve().parents[1] +temporary = Path(os.environ.get("TMPDIR", str(ROOT / "out/tmp"))) +temporary.mkdir(parents=True, exist_ok=True) +with tempfile.TemporaryDirectory(prefix="reliefnt-net-rx-", dir=temporary) as work: + binary = Path(work) / "net-rx" + subprocess.run(["clang", "-std=c11", "-O1", "-g", "-Wall", "-Wextra", "-Werror", + "-fsanitize=address,undefined", "-fno-sanitize-recover=all", + "-Iinclude", "-Iinclude/uapi", "tools/tests/net_rx_budget_test.c", + "net/input.c", "-o", str(binary)], cwd=ROOT, check=True) + subprocess.run([str(binary)], check=True, timeout=20) diff --git a/tools/test_pci_msix.py b/tools/test_pci_msix.py new file mode 100644 index 00000000..f7ed599b --- /dev/null +++ b/tools/test_pci_msix.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +"""Verify production MSI-X allocation and IRQ lifetime at the PCI boundary.""" +from pathlib import Path +import os +import subprocess +import tempfile + +ROOT = Path(__file__).resolve().parents[1] +temporary = Path(os.environ.get("TMPDIR", str(ROOT / "out/tmp"))) +temporary.mkdir(parents=True, exist_ok=True) +with tempfile.TemporaryDirectory(prefix="reliefnt-msix-", dir=temporary) as work: + binary = Path(work) / "msix" + subprocess.run(["clang", "-std=c11", "-O1", "-g", "-Wall", "-Wextra", "-Werror", + "-fsanitize=address,undefined", "-fno-sanitize-recover=all", + "-Iinclude", "-Iinclude/uapi", "tools/tests/pci_msix_test.c", + "arch/x86_64/platform/pci_irq.c", "-o", str(binary)], cwd=ROOT, check=True) + subprocess.run([str(binary)], check=True, timeout=20) diff --git a/tools/test_vmxnet3.py b/tools/test_vmxnet3.py index 3c63d27e..af76a79a 100644 --- a/tools/test_vmxnet3.py +++ b/tools/test_vmxnet3.py @@ -7,7 +7,7 @@ ROOT = Path(__file__).resolve().parents[1] SOURCES = ["tools/tests/vmxnet3_test.c", *[ - "drivers/net/vmxnet3/" + name + ".c" for name in ("main", "hardware", "rings")]] + "drivers/net/vmxnet3/" + name + ".c" for name in ("main", "hardware", "rings", "interrupt")]] def main(): diff --git a/tools/tests/host-suites.list b/tools/tests/host-suites.list index 72f09844..f1f94f0e 100644 --- a/tools/tests/host-suites.list +++ b/tools/tests/host-suites.list @@ -13,6 +13,7 @@ e1000 tools/test_e1000.py e1000e tools/test_e1000e.py r8169 tools/test_r8169.py vmxnet3 tools/test_vmxnet3.py +pci_msix tools/test_pci_msix.py efi_fs_early tools/test_efi_fs_early.py efi_handoff tools/test_efi_handoff.py efi_acpi_bootstrap tools/test_efi_acpi_bootstrap.py @@ -218,5 +219,6 @@ physical_metadata tools/test_physical_metadata.py heap_slab tools/test_heap_slab.py vfs_lookup_cache tools/test_vfs_lookup_cache.py net_device tools/test_net_device.py +net_rx_budget tools/test_net_rx_budget.py net_multi_interface tools/test_net_multi_interface.py net_multinic_data tools/test_net_multinic_data.py diff --git a/tools/tests/ipv6_protocol_test.c b/tools/tests/ipv6_protocol_test.c index f7912924..375d0fcd 100644 --- a/tools/tests/ipv6_protocol_test.c +++ b/tools/tests/ipv6_protocol_test.c @@ -129,6 +129,11 @@ int e1000_poll(void *frame,uint32_t capacity,uint32_t *len) *len=queued_length;queued_length=0;return 1; } int netdev_poll(uint32_t index,void *frame,uint32_t capacity,uint32_t *len) { if(index==2)return e1000_poll(frame,capacity,len);*len=0;return 0; } +/* This fixture models poll-only NICs; IRQ admission has a separate host suite. */ +uint32_t netdev_rx_take(uint32_t after) { (void)after;return 0; } +void netdev_rx_notify(uint32_t index) { (void)index; } +int netdev_poll_notified(uint32_t index,void *frame,uint32_t capacity,uint32_t *len) +{ return netdev_poll(index,frame,capacity,len); } /** @brief Ignore packet socket mirroring. @param frame Bytes. @param length Byte length. */ void net_packet_input(const void *frame,uint32_t length) { (void)frame;(void)length; } void net_packet_input_on(uint32_t index,const void *frame,uint32_t length) diff --git a/tools/tests/net_device_test.c b/tools/tests/net_device_test.c index 26554b68..ebe0136a 100644 --- a/tools/tests/net_device_test.c +++ b/tools/tests/net_device_test.c @@ -6,6 +6,12 @@ #include "../../kernel/device/manager_internal.h" #include #include +#include + +extern void netdev_rx_notify(uint32_t) __attribute__((weak)); +extern uint32_t netdev_rx_take(uint32_t) __attribute__((weak)); +static unsigned wakeups; +void kernel_deferred_request(enum kernel_deferred_service service) { (void)service; ++wakeups; } int32_t loading_slot = -1; struct driver_slot driver_slots[RELIEFOS_DRIVER_MAX]; @@ -42,7 +48,16 @@ int main(void) assert(!driver_register_netdev(&ops, &a, &ia)); assert(!driver_register_netdev(&ops, &b, &ib)); assert(ia == 2 && ib == 3 && netdev_next(0) == 0 && !attaches); + if (!netdev_rx_notify || !netdev_rx_take) { + fputs("FAIL: IRQ receive notification is unavailable\n", stderr); return 1; + } + netdev_rx_notify(ia); /* An early IRQ is retained until publication. */ + assert(!netdev_rx_take(0)); driver_manager_service_enable(0); driver_netdev_publish_owner(0); + assert(netdev_rx_take(0)==ia && !netdev_rx_take(0)); + netdev_rx_notify(ia); netdev_rx_notify(ia); netdev_rx_notify(ib); + assert(netdev_rx_take(ia)==ib && netdev_rx_take(ib)==ia && !netdev_rx_take(0)); + assert(wakeups); loading_slot = 1; assert(!driver_register_netdev(&ops, &c, &ic) && ic == 4); driver_manager_service_enable(1); driver_netdev_publish_owner(1); @@ -61,9 +76,16 @@ int main(void) assert(netdev_poll(ic, &byte, 1, &length) == -19 && length == 0); netdev_counters(ic, &counts); assert(counts.rx_packets == 1 && !counts.rx_errors && !counts.rx_drops); + assert(netdev_poll_notified(ic,&byte,1,&length)==1 && length==1); + netdev_counters(ic,&counts); assert(counts.rx_packets==2 && !counts.rx_errors); c.link_down = 0; driver_manager_service_close(0); driver_manager_service_drain(0); + netdev_rx_notify(ia); driver_netdev_remove_owner(0); + assert(!netdev_rx_take(0)); + unsigned before_wakeups=wakeups; + netdev_rx_notify(ia); netdev_rx_notify(0xffffffffu); + assert(wakeups==before_wakeups && !netdev_rx_take(0)); assert(detaches == 2 && detached[0] == ia && detached[1] == ib); assert(netdev_next(0) == ic && !netdev_is_ready(ia)); struct e1000_info absent = {.present = 1}; netdev_get_info(ia, &absent); diff --git a/tools/tests/net_rx_budget_test.c b/tools/tests/net_rx_budget_test.c new file mode 100644 index 00000000..d5e8e868 --- /dev/null +++ b/tools/tests/net_rx_budget_test.c @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Exercise the real receive dispatcher against finite NIC completion queues. */ +#include +#include +#include +#include "../../net/internal.h" +#include + +extern void net_poll_rx_budget(uint32_t) __attribute__((weak)); +static unsigned frames[2], pending[2], delivered[2], attempts, timers; +static unsigned dropped; +static bool down; +uint32_t netdev_rx_take(uint32_t after) +{ + for (unsigned pass=0;pass<2;++pass) for (unsigned i=0;i<2;++i) + if (pending[i] && (pass || i+2>after)) { pending[i]=0; return i+2; } + return 0; +} +void netdev_rx_notify(uint32_t id) { assert(id>=2 && id<=3); pending[id-2]=1; } +uint32_t netdev_next(uint32_t after) { return after<2 ? 2 : after==2 ? 3 : 0; } +bool net_interface_is_up(uint32_t id) { return id>=2 && id<=3 && !down; } +int netdev_poll(uint32_t id,void *frame,uint32_t capacity,uint32_t *length) +{ + assert(id>=2 && id<=3 && capacity>=64); ++attempts; *length=0; + if (!frames[id-2]) return 0; + --frames[id-2]; + if (dropped) { --dropped; return -74; } + memset(frame,0,64); *length=64; return 1; +} +int netdev_poll_notified(uint32_t id,void *frame,uint32_t capacity,uint32_t *length) +{ return netdev_poll(id,frame,capacity,length); } +void net_packet_input_on(uint32_t id,const void *frame,uint32_t length) +{ assert(frame && length==64); ++delivered[id-2]; } +int net_frame_for_us_on(uint32_t id,const uint8_t *frame) { (void)id;(void)frame;return 0; } +uint16_t net_get_u16(const uint8_t *data) { return (uint16_t)data[0]<<8|data[1]; } +void net_handle_arp_on(uint32_t id,const uint8_t *p,uint32_t n,struct net_arp_wait *w) +{ (void)id;(void)p;(void)n;(void)w; } +void net_handle_ipv4_on(uint32_t id,const uint8_t *p,uint32_t n,struct net_ping_wait *a, + struct net_udp_wait *b,struct net_tcp_wait *c) { (void)id;(void)p;(void)n;(void)a;(void)b;(void)c; } +void net_ipv6_input_on(uint32_t id,const uint8_t *p,uint32_t n) { (void)id;(void)p;(void)n; } +void net_tcp_service_sockets(void) { ++timers; } +void net_ipv6_poll(void) {} +void net_device_retry_registration(void) {} +bool net_device_registration_pending(void) { return false; } +bool net_tcp_maintenance_pending(void) { return false; } +bool net_ipv6_maintenance_pending(void) { return false; } +uint64_t time_ticks(void) { return 0; } +int main(void) +{ + if (!net_poll_rx_budget) { fputs("FAIL: budgeted IRQ receive service is unavailable\n",stderr); return 1; } + frames[0]=frames[1]=100; pending[0]=pending[1]=1; + net_poll_rx_budget(32); + assert(attempts==32 && delivered[0] && delivered[1]); + assert(delivered[0]+delivered[1]==32 && pending[0] && pending[1]); + assert(timers && timers<=32); + dropped=100; unsigned before=attempts; + net_poll_rx_budget(32); assert(attempts-before==32); + dropped=0; frames[0]=frames[1]=0; + before=attempts; net_poll_rx_budget(32); + assert(attempts-before==2 && !pending[0] && !pending[1]); + before=attempts; net_poll_rx_budget(32); assert(attempts==before); + net_poll_rx_budget(0); assert(attempts==before); + down=true; frames[0]=1; pending[0]=1; + unsigned old_delivered=delivered[0]; before=attempts; + net_poll_rx_budget(32); + assert(attempts-before==2 && !pending[0] && delivered[0]==old_delivered); + puts("PASS network IRQ polling: bounded bursts, NIC fairness, drops and idle completion"); + return 0; +} diff --git a/tools/tests/pci_msix_test.c b/tools/tests/pci_msix_test.c new file mode 100644 index 00000000..3bc82874 --- /dev/null +++ b/tools/tests/pci_msix_test.c @@ -0,0 +1,89 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Real IRQ allocation/dispatch against a PCI config and UC table boundary. */ +#include +#include +#include +#include +#include +#include + +extern int pci_request_msix_irq(const struct reliefos_driver_pci_device *, + void (*)(void *), void *, uint32_t *) __attribute__((weak)); +static uint32_t config[64], table[1024]; +static unsigned maps, fail_mapping, table_accesses, calls; +static bool apic_on = true; +uint16_t apic_bsp_id(void) { return 3; } +bool apic_enabled(void) { return apic_on; } +void kernel_spin_lock_irqsave(struct kernel_spinlock *lock, uint64_t *flags) +{ assert(!lock->state); lock->state=1; *flags=0; } +void kernel_spin_unlock_irqrestore(struct kernel_spinlock *lock, uint64_t flags) +{ (void)flags; assert(lock->state); lock->state=0; } +void kernel_execution_lock_irqsave(uint64_t *flags) { *flags=0; } +void kernel_execution_unlock_irqrestore(uint64_t flags) { (void)flags; } +uint32_t pci_config_read32(uint8_t b,uint8_t s,uint8_t f,uint8_t o) +{ (void)b;(void)s;(void)f; return config[o/4]; } +uint16_t pci_config_read16(uint8_t b,uint8_t s,uint8_t f,uint8_t o) +{ return (uint16_t)(pci_config_read32(b,s,f,o)>>((o&2)*8)); } +void pci_config_write32(uint8_t b,uint8_t s,uint8_t f,uint8_t o,uint32_t v) +{ (void)b;(void)s;(void)f; config[o/4]=v; } +void pci_config_write16(uint8_t b,uint8_t s,uint8_t f,uint8_t o,uint16_t v) +{ unsigned shift=(o&2)*8; uint32_t old=pci_config_read32(b,s,f,o); config[o/4]=(old&~(0xffffu<vendor_id==0x15ad && dev->device_id==0x07b0 && bar==2 && + pa>=0xd0000000 && pa<0xd0002000 && bytes && bytes<=0xd0002000-pa; } +void *pci_map_device_bar(const struct pci_device *dev,uint8_t bar,uint64_t pa,uint64_t bytes) +{ + ++table_accesses; + assert(pci_device_bar_contains(dev,bar,pa,bytes)); + if (fail_mapping) return NULL; + assert(pa==0xd0000000 && bytes==4096); ++maps; return table; +} +void pci_unmap_mmio(void *p,uint64_t bytes) { assert(p==table && bytes==4096 && maps); --maps; } +static void handler(void *context) { ++*(unsigned *)context; } +static void reset(void) +{ + assert(!maps); memset(config,0,sizeof(config)); memset(table,0,sizeof(table)); + config[0]=0x07b015ad; config[1]=1u<<20; config[0x34/4]=0x40; + config[0x40/4]=0x00030011; /* Four entries, table BAR2+0x80, PBA BAR2+0x1000. */ + config[0x44/4]=0x82; config[0x48/4]=0x1002; config[0x18/4]=0xd0000000; + fail_mapping=table_accesses=0; +} +int main(void) +{ + if (!pci_request_msix_irq) { fputs("FAIL: MSI-X IRQ allocation is unavailable\n",stderr); return 1; } + struct reliefos_driver_pci_device dev={.vendor_id=0x15ad,.device_id=0x07b0}; + uint32_t h=0; + reset(); apic_on=false; + assert(pci_request_msix_irq(&dev,handler,&calls,&h)==-95 && !maps); apic_on=true; + assert(pci_request_msix_irq(NULL,handler,&calls,&h)==-22); + config[0x40/4]=0x4011; /* Cycle with no valid MSI-X capability length beyond end. */ + config[0x34/4]=0xfc; config[0xfc/4]=0x11; + assert(pci_request_msix_irq(&dev,handler,&calls,&h)<0 && !table_accesses); + reset(); config[0x44/4]=0x86; /* Reserved BIR. */ + assert(pci_request_msix_irq(&dev,handler,&calls,&h)<0 && !table_accesses); + reset(); config[0x48/4]=0x82; /* Table and PBA overlap. */ + assert(pci_request_msix_irq(&dev,handler,&calls,&h)<0 && !table_accesses); + reset(); config[0x40/4]=0x07ff0011; /* Table exceeds its BAR. */ + assert(pci_request_msix_irq(&dev,handler,&calls,&h)<0 && !table_accesses); + reset(); fail_mapping=1; + assert(pci_request_msix_irq(&dev,handler,&calls,&h)<0 && !maps && !(config[0x40/4]&0x80000000)); + reset(); + assert(!pci_request_msix_irq(&dev,handler,&calls,&h) && maps==1); + assert((config[0x40/4]&0xc0000000)==0x80000000); + assert(table[0x80/4]==0xfee03000 && table[0x84/4]==0); + unsigned vector=table[0x88/4]; assert(vector>=0x50 && vector<=0x5f); + assert(!(table[0x8c/4]&1)); + for (unsigned i=1;i<4;++i) assert(table[(0x8c+16*i)/4]&1); + assert(pci_request_msix_irq(&dev,handler,&calls,&h)==-16 && maps==1); + pci_irq_dispatch(vector); assert(calls==1); + uint32_t old=h; pci_free_irq(h); assert(!maps); + assert((config[0x40/4]&0xc0000000)==0x40000000 && (table[0x8c/4]&1)); + assert(!pci_request_msix_irq(&dev,handler,&calls,&h)); + assert(table[0x88/4]!=vector); + pci_irq_dispatch(vector); assert(calls==1); + pci_free_irq(old); assert(maps==1 && (config[0x40/4]&0x80000000)); + pci_irq_dispatch(table[0x88/4]); assert(calls==2); + pci_free_irq(h); assert(!maps); + puts("PASS MSI-X: bounds, overlap, rollback, masks, routing, dispatch and retired vectors"); + return 0; +} diff --git a/tools/tests/vmxnet3_perf_guest.c b/tools/tests/vmxnet3_perf_guest.c new file mode 100644 index 00000000..06386461 --- /dev/null +++ b/tools/tests/vmxnet3_perf_guest.c @@ -0,0 +1,120 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Linux/POSIX socket probe: verified TCP echo throughput and UDP round trips. */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** @brief Abort a failed probe with the failing operation and errno. */ +static void fail(const char *operation) { perror(operation); exit(1); } +/** @brief Read nanoseconds from a supported POSIX clock. */ +static uint64_t now(clockid_t clock) +{ + struct timespec ts; + if (clock_gettime(clock,&ts)) fail("clock_gettime"); + return (uint64_t)ts.tv_sec*1000000000u+(uint64_t)ts.tv_nsec; +} +/** @brief Read POSIX per-process user/system CPU time without optional CPU clocks. */ +static uint64_t process_cpu(void) +{ + struct rusage usage; + if (getrusage(RUSAGE_SELF,&usage)) fail("getrusage"); + return ((uint64_t)usage.ru_utime.tv_sec+(uint64_t)usage.ru_stime.tv_sec)*1000000000u+ + ((uint64_t)usage.ru_utime.tv_usec+(uint64_t)usage.ru_stime.tv_usec)*1000u; +} +/** @brief Read Linux aggregate user/system/idle accounting in USER_HZ ticks. */ +static void cpu(uint64_t *total,uint64_t *busy) +{ + unsigned long long user,nice,system,idle,wait,irq,soft,steal; + FILE *file=fopen("/proc/stat","r"); + if (!file) fail("/proc/stat"); + int count=fscanf(file,"cpu %llu %llu %llu %llu %llu %llu %llu %llu", + &user,&nice,&system,&idle,&wait,&irq,&soft,&steal); + fclose(file); + if (count!=8) { errno=EIO; fail("parse /proc/stat"); } + *busy=user+nice+system+irq+soft+steal; *total=*busy+idle+wait; +} +/** @brief Open a connected host echo socket on one Linux interface. */ +static int connect_peer(const char *interface,const char *host,unsigned port,int type) +{ + int fd=socket(AF_INET,type,0); + if (fd<0) fail("socket"); + if (setsockopt(fd,SOL_SOCKET,SO_BINDTODEVICE,interface,strlen(interface)+1)) fail("SO_BINDTODEVICE"); + struct sockaddr_in address={.sin_family=AF_INET,.sin_port=htons((uint16_t)port)}; + if (inet_pton(AF_INET,host,&address.sin_addr)!=1) { errno=EINVAL; fail("inet_pton"); } + if (connect(fd,(void *)&address,sizeof(address))) fail("connect"); + return fd; +} +/** @brief Compare unsigned RTT samples for percentile selection. */ +static int compare(const void *a,const void *b) +{ uint64_t x=*(const uint64_t *)a,y=*(const uint64_t *)b;return (x>y)-(x65535 || !bytes || bytes>1024u*1024u*1024u) return 2; + int fd=connect_peer(argv[1],argv[2],port,SOCK_STREAM); + int flags=fcntl(fd,F_GETFL); + if (flags<0 || fcntl(fd,F_SETFL,flags|O_NONBLOCK)<0) fail("nonblocking socket"); + uint8_t tx[8192],rx[8192]; + uint64_t total0,busy0,total1,busy1; + cpu(&total0,&busy0); + uint64_t process0=process_cpu(), start=now(CLOCK_MONOTONIC); + size_t sent=0,received=0; + while (receivedsizeof(tx)) n=sizeof(tx); + for (size_t i=0;i0) sent+=(size_t)result; + else if (result<0 && errno!=EINTR && errno!=EAGAIN && errno!=EWOULDBLOCK) fail("TCP send"); + } + if (p.revents&(POLLIN|POLLHUP)) { + ssize_t n=recv(fd,rx,sizeof(rx),0); + if (!n) { errno=EPIPE;fail("early TCP EOF"); } + if (n<0) { if (errno==EINTR || errno==EAGAIN || errno==EWOULDBLOCK) continue;fail("TCP receive"); } + if ((size_t)n>bytes-received) { errno=EIO;fail("extra TCP data"); } + for (ssize_t i=0;i120000000000ull) { errno=ETIMEDOUT;fail("TCP deadline"); } + } + uint64_t elapsed=now(CLOCK_MONOTONIC)-start, process=process_cpu()-process0; + cpu(&total1,&busy1); close(fd); + fd=connect_peer(argv[1],argv[2],port,SOCK_DGRAM); + uint64_t samples[128]; + for (unsigned i=0;i<128;++i) { + memset(tx,(int)i,64); uint64_t before=now(CLOCK_MONOTONIC); + if (send(fd,tx,64,0)!=64) fail("UDP send"); + struct pollfd p={.fd=fd,.events=POLLIN}; + if (poll(&p,1,3000)!=1 || recv(fd,rx,sizeof(rx),0)!=64 || memcmp(tx,rx,64)) { + errno=EIO;fail("UDP echo"); + } + samples[i]=now(CLOCK_MONOTONIC)-before; + } + close(fd); qsort(samples,128,sizeof(samples[0]),compare); + printf("VMXNET3_PERF {\"bytes\":%zu,\"elapsed_ns\":%llu,\"process_cpu_ns\":%llu," + "\"cpu_total_ticks\":%llu,\"cpu_busy_ticks\":%llu,\"udp_p50_ns\":%llu,\"udp_p95_ns\":%llu}\n", + bytes,(unsigned long long)elapsed,(unsigned long long)process, + (unsigned long long)(total1-total0),(unsigned long long)(busy1-busy0), + (unsigned long long)samples[63],(unsigned long long)samples[121]); + return 0; +} diff --git a/tools/tests/vmxnet3_test.c b/tools/tests/vmxnet3_test.c index 60b6c155..ac468bab 100644 --- a/tools/tests/vmxnet3_test.c +++ b/tools/tests/vmxnet3_test.c @@ -20,10 +20,15 @@ struct model { unsigned tx_size, rx_size, rxc_size; const struct reliefnt_netdev_ops *ops; void *context; + void (*irq)(void *); + void *irq_context; + unsigned irq_handle, irq_notifications, link_queries, inject_rearm, rx_doorbells, intr_config; }; static struct model models[2]; static unsigned count=1, live, maps, allocation_limit=32, registered, teardown_error, allocation_owner; static uint64_t next_pa=0x140000000ULL; +static int msix_result=-95, msi_result=-95; +static unsigned msix_attempts, msi_attempts; static struct allocation { uint64_t pa; uint32_t pages; void *data; unsigned owner; } allocations[32]; /** @brief Allocate host storage for driver-owned metadata. @param size Bytes. @return Zeroed storage. */ @@ -108,11 +113,41 @@ static void log_text(enum console_log_level level,const char *fmt,...) { (void)l /** @brief Capture one NIC registration. @param ops Driver operations. @param context Per-device state. @param index Returned index. @return Zero. */ int driver_register_netdev(const struct reliefnt_netdev_ops *ops,void *context,uint32_t *index) { assert(registeredslot-3]; assert(!m->activated && !m->irq); + m->irq=handler; m->irq_context=context; *handle=m->irq_handle=p->slot; + return 0; +} +/** @brief Model the legacy MSI provider for fallback and explicit MSI preference. */ +static int request_msi(const struct reliefos_driver_pci_device *p, + void (*handler)(void *),void *context,uint32_t *handle) +{ + ++msi_attempts; + if (msi_result) return msi_result; + struct model *m=&models[p->slot-3]; assert(!m->activated && !m->irq); + m->irq=handler; m->irq_context=context; *handle=m->irq_handle=p->slot; + return 0; +} +/** @brief Synchronize and remove the retained interrupt callback. */ +static void free_irq(uint32_t handle) +{ + struct model *m=&models[handle-3]; + assert(m->bar[0][0]==1); m->irq=NULL; m->irq_context=NULL; m->irq_handle=0; +} +/** @brief Record allocation-free notifications, including the init/publication handoff. */ +void netdev_rx_notify(uint32_t id) +{ assert(id && id<=count); ++models[id-1].irq_notifications; } static const struct reliefos_driver_kernel_api api={ .abi_version=RELIEFOS_DRIVER_ABI_VERSION,.struct_size=sizeof(api), .pci_enumerate=enumerate,.pci_read16=read16,.pci_write16=write16,.pci_read32=read32, .map_mmio=map,.unmap_mmio=unmap,.alloc_dma=allocate,.free_dma=release,.phys_to_virt=alias, .sleep_ms=sleep_ms,.console_log=log_text,.report_teardown_failure=report_failure, + .request_pci_irq=request_msi,.free_pci_irq=free_irq, }; /** @brief Find the device associated with an MMIO mapping. @param p Register mapping. @param which Returned BAR index. @return Device model. */ @@ -138,7 +173,8 @@ uint32_t vmx_io_read(void *p,unsigned off) uint32_t cmd=m->bar[1][off/4]; if (cmd==0xcafe0000) return m->activated ? 0 : 1; if (cmd==0xcafe0001 || cmd==0xcafe0002) return m->fail_stop ? 1 : 0; - if (cmd==0xf00d0002) return m->link ? 0x03e80001 : 0; + if (cmd==0xf00d0002) { ++m->link_queries; return m->link ? 0x03e80001 : 0; } + if (cmd==0xf00d0008) return m->intr_config; return 0; } return m->bar[bar][off/4]; @@ -146,7 +182,14 @@ uint32_t vmx_io_read(void *p,unsigned off) /** @brief Issue a modeled VMXNET3 register write. @param p BAR mapping. @param off Register offset. @param value Word. */ void vmx_io_write(void *p,unsigned off,uint32_t value) { - unsigned bar; struct model *m=lookup(p,&bar); m->bar[bar][off/4]=value; + unsigned bar; struct model *m=lookup(p,&bar); + if (!bar && off==0x800) ++m->rx_doorbells; + if (bar==1 && off==0x40) { m->bar[bar][off/4]&=~value; return; } + m->bar[bar][off/4]=value; + if (!bar && !off && !value && m->inject_rearm) { + --m->inject_rearm; + m->rxc[0].address=3u<<14; m->rxc[0].a=64; m->rxc[0].b=0x80000000; + } if (bar==1 && off==0x10) m->shared=(m->shared&0xffffffff00000000ULL)|value; if (bar==1 && off==0x18) m->shared=(m->shared&0xffffffffULL)|((uint64_t)value<<32); if (bar!=1 || off!=0x20) return; @@ -168,7 +211,8 @@ void vmx_io_write(void *p,unsigned off,uint32_t value) static void reset(void) { assert(!live && !maps); memset(models,0,sizeof(models)); count=1; registered=0; - teardown_error=0; allocation_limit=32; + teardown_error=0; allocation_limit=32; msix_result=msi_result=-95; + msix_attempts=msi_attempts=0; for (unsigned i=0;i<2;++i) { models[i].version=models[i].upt=models[i].link=1; models[i].command=7; } } /** @brief Stop all controllers and verify resources were returned. */ @@ -177,6 +221,68 @@ static void finish(void) vmxnet3_driver_module.fini(); assert(!teardown_error && !live && !maps); for (unsigned i=0;iirq && m->irq_notifications && !word(alias(m->shared),108)); + assert(((const uint8_t *)alias(m->shared))[80]==1); + assert(m->rx_doorbells==1); + assert(!m->ops->poll(m->context,out,sizeof(out),&length) && !m->bar[0][0]); + unsigned queries=m->link_queries; + for (unsigned i=0;i<100;++i) assert(m->ops->is_ready(m->context)); + assert(m->link_queries==queries); /* No GET_LINK for each packet. */ + unsigned notify=m->irq_notifications; + m->irq(m->irq_context); + assert(m->bar[0][0]==1 && m->irq_notifications==notify+1); + m->inject_rearm=1; + assert(!m->ops->poll(m->context,out,sizeof(out),&length)); + assert(m->bar[0][0]==1 && m->irq_notifications>notify+1); + assert(m->ops->poll(m->context,out,sizeof(out),&length)==1 && length==64); + assert(m->rx_doorbells==1); /* updateRxProd=false avoids per-packet MMIO. */ + ((uint8_t *)alias(m->shared))[1024+256]=1; + m->rxc[1].address=1u|(3u<<14); m->rxc[1].a=64; m->rxc[1].b=0x80000000; + assert(m->ops->poll(m->context,out,sizeof(out),&length)==1 && length==64); + assert(m->rx_doorbells==2); /* Honor an explicit producer-update request. */ + assert(!m->ops->poll(m->context,out,sizeof(out),&length) && !m->bar[0][0]); + m->link=0; m->bar[1][0x40/4]=4; m->irq(m->irq_context); + assert(!m->ops->poll(m->context,out,sizeof(out),&length)); + assert(!m->ops->is_ready(m->context) && !m->bar[1][0x40/4]); + m->link=1; m->bar[1][0x40/4]=4; m->irq(m->irq_context); + assert(!m->ops->poll(m->context,out,sizeof(out),&length) && m->ops->is_ready(m->context)); + m->bar[1][0x40/4]=1; m->irq(m->irq_context); + assert(m->ops->poll(m->context,out,sizeof(out),&length)<0); + assert(!m->ops->is_ready(m->context) && m->bar[0][0]==1); + finish(); assert(!m->irq); + puts("PASS vmxnet3 IRQ mask, cached carrier, rearm race, link/queue events and teardown"); +} +/** @brief Check negotiated MSI fallback, polling and IRQ lifecycle rollback. */ +static void interrupt_fallbacks(void) +{ + reset(); msi_result=0; + assert(!vmxnet3_driver_module.init(&api)); + assert(msix_attempts==1 && msi_attempts==1 && models[0].irq); + finish(); assert(!models[0].irq); + reset(); msix_result=msi_result=0; models[0].intr_config=2u|(1u<<2); + assert(!vmxnet3_driver_module.init(&api)); + assert(!msix_attempts && msi_attempts==1 && models[0].irq); + assert(!((uint8_t *)alias(models[0].shared))[80]); /* Active mask mode. */ + finish(); + reset(); msix_result=msi_result=0; models[0].intr_config=1; + assert(!vmxnet3_driver_module.init(&api)); + assert(!msix_attempts && !msi_attempts && !models[0].irq); + assert(word(alias(models[0].shared),108)==1); /* No speculative INTx. */ + finish(); + reset(); msix_result=0; models[0].fail_activate=1; + assert(vmxnet3_driver_module.init(&api)<0); finish(); assert(!models[0].irq); + reset(); msix_result=0; + assert(!vmxnet3_driver_module.init(&api)); + models[0].fail_stop=1; vmxnet3_driver_module.fini(); + assert(teardown_error && live && maps && !models[0].irq); + models[0].fail_stop=0; teardown_error=0; finish(); + puts("PASS vmxnet3 MSI preference/fallback, polling and IRQ failed-stop retention"); +} /** @brief Test probing, DMA ownership, packet rings and malformed completions. @return Zero on success. */ int main(void) { @@ -238,6 +344,8 @@ int main(void) m->rxc[1].address=1u|(1u<<14); m->rxc[1].a=64; m->rxc[1].b=0x83000000u; assert(m->ops->poll(m->context,out,sizeof(out),&bad_length)==-74 && !bad_length); finish(); + interrupts(); + interrupt_fallbacks(); reset(); assert(!vmxnet3_driver_module.init(&api)); m=&models[0]; m->fail_busmaster_disable=1; vmxnet3_driver_module.fini(); assert(teardown_error && live && maps);