interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / kernel / dev / net_bind.h

78 lines · 4152 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* net_bind.h -- bind native/net's polled virtio-net driver
18 * (aienos_virtio_net.c) to the virtio-net PCI function through ck.h services
19 * and run one bounded UDP round trip (QEMU user networking).
20 *
21 * DMA rule (same as NVMe, dev/nvme_bind.c): no SMMU confinement means no DMA.
22 * The driver's one shared region (rings + packet buffers) is allocated first
23 * and becomes the stream's only SMMU window (ck_dma_confine); only then are
24 * memory decoding and bus mastering enabled. Without an SMMU, or when the
25 * SMMU did not come up, the device stays off. There is no unconfined bypass
26 * for virtio-net, not even in the TEST-ONLY CK_QEMU_UNSAFE_DMA=1 build.
27 *
28 * ACCESS_PLATFORM: vnet_init_flags(..., VNET_INIT_REQUIRE_ACCESS_PLATFORM)
29 * negotiates VIRTIO_F_ACCESS_PLATFORM (bit 33) and refuses a device that does
30 * not offer it (fail closed: QEMU virtio-pci without iommu_platform=on DMAs
31 * around the vIOMMU). With it, every ring and buffer access of the device
32 * goes through the SMMU window; the kernel prints access_platform=yes.
33 *
34 * Fence proof (after the good round trip, net_bind.c smmu_negative_test):
35 * the RX descriptors the device holds are pointed at a pattern page outside
36 * the window and a datagram draws a reply; the SMMU must log F_TRANSLATION
37 * for this stream at that page, the page must stay intact. Measured on QEMU
38 * 8.2.2: no NEEDS_RESET; QEMU completes the RX through its internal bounce
39 * buffer (rx_completed=1) while the refused write never reaches the page.
40 * The binding discards the redirected descriptors, resets and re-inits the
41 * device and runs a second round trip inside the window. */
42#ifndef AIENOS_CK_NET_BIND_H
43#define AIENOS_CK_NET_BIND_H
44#include "aienos_virtio_net.h"
45#include "pci.h"
46
47#define CK_NET_QSIZE 64u
48
49enum {
50 CK_NET_OK = 0,
51 CK_NET_E_ARG = -501, /* bad function, BAR or capability window */
52 CK_NET_E_DMA = -502, /* DMA region allocation failed */
53 CK_NET_E_DENIED = -503, /* no SMMU confinement: device left off */
54 CK_NET_E_INIT = -504, /* vnet_init failed */
55 CK_NET_E_ARP = -505, /* no ARP reply from the gateway in time */
56 CK_NET_E_TX = -506, /* frame build, post or completion failed */
57 CK_NET_E_RX = -507, /* no matching UDP reply in time, or device broken */
58 CK_NET_E_SMMU = -508, /* SMMU negative test, its recovery, or a refused release abort */
59};
60
61/* Attach (DMA gate, BAR map, bus master, vnet_init_flags with
62 * ACCESS_PLATFORM required), then ARP for the gateway and one UDP datagram to
63 * CK_NET_ECHO_PORT and back, then the SMMU fence test and its recovery round
64 * trip (CK_NET_E_SMMU if either fails), every wait bounded by ck_time_us.
65 * Leaves the device released (reset, bus master off, stream back to abort)
66 * before returning, unless the SMMU refuses the abort: the stream then stays
67 * confined, ck_net_live stays 1, and the bind returns CK_NET_E_SMMU. A bus
68 * master that will not clear is still live, but that is not an SMMU refusal:
69 * the original error stands (a passing selftest still returns CK_NET_E_SMMU). */
70int ck_net_bind_selftest(const pci_func *f, const virtio_pci_caps *caps);
71
72/* Reset the device, revoke bus mastering and return the SMMU stream to
73 * abort if still live; prints the dma_gate/smmu lines. Idempotent. A
74 * refused abort keeps the stream confined; calling again retries it. */
75void ck_net_release(void);
76/* 1 while the device may still DMA (bus master on or stream confined). */
77int ck_net_live(void);
78#endif