History log of /netbsd-current/sys/dev/pci/virtio.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.81 10-Feb-2024 isaki

Split KASSERT(A && B) into KASSERT(A); KASSERT(B).


# 1.80 09-Feb-2024 andvar

fix spelling mistakes, mainly in comments and log messages.


Revision tags: thorpej-ifq-base thorpej-altq-separation-base
# 1.79 07-Nov-2023 rin

virtio_read_device_config_le_[24]: Fix for {aarch64,arm}eb

Stop byte-swapping for big-endian aarch64 and arm to fix
corrupted read for, e.g., sc_taglen for vio9p(4).

As described as comments in virtio_pci.c, big-endian aarch64 and
armv7 (armeb) are somewhat special. At the moment, all supported
virtual/real machines are configured as little-endian, and only
CPU cores are switched to big-endian mode during early boot stage.

Most peripheral buses for armeb are LSB as a result, and their
default bus_space(9) functions swap byte-order. Therefore, PIOed
data from memory-mapped devices, as well as pci(4) ones, are
actually LSB, but observed as MSB for armeb.

Therefore, we should not swap byte-order further in
virtio_read_device_config_le_[24] on armeb.

Thanks ozaki-r@ for comments.

XXX Centralize?
See virtio_pci.c and sys/dev/fdt/virtio_mmio_fdt.c also.


# 1.78 21-Apr-2023 yamaguchi

virtio(4): change members of struct vring_desc_extra before free a slot

This prevents the following race condition.
1. Thread-A: calls virtio_dequeue_commit() and
puts a slot into free descriptor chain in vq_free_slot()
2. Thread-B: calls virtio_enqueue_prep() and get the slot stored by Thread-A
3. Thread-B: calls virtio_enqueue_reserve() and
changes desc_base and desc_free_idx for the slot
4. Thread-A: changes the same members updated by Thread-B

reported by hannken, thanks.


# 1.77 19-Apr-2023 yamaguchi

virtio(4): change variable name, nfc


# 1.76 19-Apr-2023 yamaguchi

Fix not to allocate unnecessary descriptor

fixes PR/57358


# 1.75 19-Apr-2023 yamaguchi

Use enumeration for state of a child driver instead of flags
and check its detaching by using sc->sc_child in virtio_softc

pointed out by riastradh, thanks.
fixes PR/57357


# 1.74 31-Mar-2023 yamaguchi

Added flags to store status of attaching a virtio device

This prevents a panic on reboot after a virtio device had called
virtio_child_attach_failed().


# 1.73 31-Mar-2023 yamaguchi

Use descriptor chain for free slots instead of vq_entry list

Descriptors can be chained by themself. And descriptors added to
avail ring or used ring are already chained. But it was not used
for unused descriptors and another linked list structure named
vq_entry was used.
The chain is also used for unused descriptors to make virtio(4)
simpler.


# 1.72 29-Mar-2023 riastradh

virtio(4): Fix sizing of virtqueue allocation.

vq->vq_avail[0].ring is a zero-length array, and thus sizeof is zero;
likewise vq->vq_used[0].ring.

Use vq->vq_avail[0].ring[0] and vq->vq_used[0].ring[0] to fix this
and restore the previous allocation sizing logic.

XXX We shouldn't use zero-length arrays here -- they are asking for
trouble like this, and C99 has a standard way to express what we're
actually trying to get at it, flexible array members.

PR kern/57304

Reported-by: syzbot+7fb1047f5dfa33b26331@syzkaller.appspotmail.com


# 1.71 27-Mar-2023 nakayama

Use PRIuBUSSIZE to print bus_size_t variables.


# 1.70 27-Mar-2023 riastradh

virtio(4): Avoid name collision with global intrhand on sparc64.

Pacifies -Werror=shadow.

No functional change intended.


# 1.69 25-Mar-2023 yamaguchi

Setup virtqueues after registering them to virtio_softc


# 1.68 24-Mar-2023 yamaguchi

Added check of pointer for allocated memory before release of resource


# 1.67 23-Mar-2023 yamaguchi

Added functions to set interrupt handler and index into virtqueue


# 1.66 23-Mar-2023 yamaguchi

Set virtqueues in virtio_child_attach_finish

The number of virtqueue maybe change in a part of VirtIO devices
(e.g. vioif(4)). And it is fixed after negotiation of features.
So the configuration is moved into the function.


# 1.65 03-Jan-2023 jakllsch

Subtly adjust criteria for notification of Virtio devices in
VIRTIO_F_RING_EVENT_IDX mode.

This fixes stalls in the vioif(4) transmit path that would happen sooner
or later, depending on interface transmit utilization, and were
particularly noticable with a NetBSD guest transmitting to its x86 KVM
host at multi-gigabit speeds.


# 1.64 30-Dec-2022 jakllsch

Fix dmamap_syncs more; the number of ring elements is vq->vq_num, not
sc->sc_nvqs.


Revision tags: netbsd-10-base
# 1.63 31-Oct-2022 simonb

branches: 1.63.2;
Use PRIx64 in a debug print macro to print a uint64_t.


# 1.62 18-Oct-2022 skrll

KNF


# 1.61 17-Oct-2022 skrll

Fix previous by using roundup (and not howmany).


# 1.60 15-Oct-2022 riastradh

virtio(4): Use howmany from sys/param.h instead of open-coding it.

howmany will divide by VIRTIO_PAGE_SIZE instead of doing &
~(VIRTIO_PAGE_SIZE - 1), but it's a constant 4096 so this should make
no difference in the compiled output except possibly at -O0.

No functional change intended.


# 1.59 15-Oct-2022 riastradh

virtio(4): Sprinkle KNF.

No functional change intended.


Revision tags: bouyer-sunxi-drm-base
# 1.58 14-Aug-2022 riastradh

virtio(4): Print numeric device type, even if unrecognized.


# 1.57 12-Aug-2022 riastradh

virtio(4): Membar and bus_dmamap_sync audit.

- Don't use membar_* for DMA.

- Sync only the header and payload of the rings separately as needed.
If we bounce, this avoids large memcpy when we only care about the
header.

- Sync uring with PREREAD before triggering anything that will return
data in it.

=> Move uring PREREAD in virtio_enqueue_commit to _before_ updating
vq->vq_avail->idx, which is the pointat which the DMA read is
triggered in the `device' (host).

=> Omit needless membar_consumer in virtio_enqueue_commit -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync uring PREREAD here.

=> XXX Does the device/host ever return unsolicited entries in the
queue, or only solicited ones? If only solicited ones, the
PREREAD in virtio_init_vq is redundant.

- Sync uring with POSTREAD before we read from it. This way the DMA
read into our buffer has finished before we read from the buffer.

=> Add missing uring POSTREAD in virtio_vq_is_enqueued, between read of
vq->vq_used_idx and return to caller, so that the caller can
safely use virtio_dequeue.

=> Add missing uring POSTREADs in virtio_start_vq_intr:
. between entry from caller and the read of vq->vq_used_idx
. between the read of vq->vq_used_idx and return to caller,
so that the caller can safely use virtio_dequeue, just like
virtio_vq_is_enqueued

=> Move uring POSTREADs in virtio_enqueue_commit to _before_ reading
vq->vq_used->flags or *vq->vq_avail_event, not after.

- After we write to aring, sync it with PREWRITE. This way we finish
writing to our buffer before the DMA write from it.

=> Omit needless PREWRITE in virtio_init_vq -- we do the appropriate
PREWRITE in virtio_enqueue_commit now.

=> Convert membar_producer to bus_dmamap_sync PREWRITE in
virtio_enqueue_commit.

=> Omit incorrect aring POSTWRITE in virtio_enqueue_commit -- no need
because the DMA write may not have completed yet at this point,
and we already do a POSTWRITE in virtio_vq_is_enqueued.

=> Omit needless membar_producer in virtio_postpone_intr -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync PREWRITE here.

- After xfers to aring have completed, sync it with POSTWRITE.

=> Add missing aring POSTWRITE in virtio_free_vq, in case there are
paths from virtio_enqueue_commit to here that don't go through
virtio_is_enqueued. (If there are no such paths, then maybe we
should KASSERT(vq->vq_queued == 0) in virtio_free_vq.)


# 1.56 09-Aug-2022 riastradh

virtio(4): Move comment for virtio_vq_intr.

No functional change intended.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.79 07-Nov-2023 rin

virtio_read_device_config_le_[24]: Fix for {aarch64,arm}eb

Stop byte-swapping for big-endian aarch64 and arm to fix
corrupted read for, e.g., sc_taglen for vio9p(4).

As described as comments in virtio_pci.c, big-endian aarch64 and
armv7 (armeb) are somewhat special. At the moment, all supported
virtual/real machines are configured as little-endian, and only
CPU cores are switched to big-endian mode during early boot stage.

Most peripheral buses for armeb are LSB as a result, and their
default bus_space(9) functions swap byte-order. Therefore, PIOed
data from memory-mapped devices, as well as pci(4) ones, are
actually LSB, but observed as MSB for armeb.

Therefore, we should not swap byte-order further in
virtio_read_device_config_le_[24] on armeb.

Thanks ozaki-r@ for comments.

XXX Centralize?
See virtio_pci.c and sys/dev/fdt/virtio_mmio_fdt.c also.


# 1.78 21-Apr-2023 yamaguchi

virtio(4): change members of struct vring_desc_extra before free a slot

This prevents the following race condition.
1. Thread-A: calls virtio_dequeue_commit() and
puts a slot into free descriptor chain in vq_free_slot()
2. Thread-B: calls virtio_enqueue_prep() and get the slot stored by Thread-A
3. Thread-B: calls virtio_enqueue_reserve() and
changes desc_base and desc_free_idx for the slot
4. Thread-A: changes the same members updated by Thread-B

reported by hannken, thanks.


# 1.77 19-Apr-2023 yamaguchi

virtio(4): change variable name, nfc


# 1.76 19-Apr-2023 yamaguchi

Fix not to allocate unnecessary descriptor

fixes PR/57358


# 1.75 19-Apr-2023 yamaguchi

Use enumeration for state of a child driver instead of flags
and check its detaching by using sc->sc_child in virtio_softc

pointed out by riastradh, thanks.
fixes PR/57357


# 1.74 31-Mar-2023 yamaguchi

Added flags to store status of attaching a virtio device

This prevents a panic on reboot after a virtio device had called
virtio_child_attach_failed().


# 1.73 31-Mar-2023 yamaguchi

Use descriptor chain for free slots instead of vq_entry list

Descriptors can be chained by themself. And descriptors added to
avail ring or used ring are already chained. But it was not used
for unused descriptors and another linked list structure named
vq_entry was used.
The chain is also used for unused descriptors to make virtio(4)
simpler.


# 1.72 29-Mar-2023 riastradh

virtio(4): Fix sizing of virtqueue allocation.

vq->vq_avail[0].ring is a zero-length array, and thus sizeof is zero;
likewise vq->vq_used[0].ring.

Use vq->vq_avail[0].ring[0] and vq->vq_used[0].ring[0] to fix this
and restore the previous allocation sizing logic.

XXX We shouldn't use zero-length arrays here -- they are asking for
trouble like this, and C99 has a standard way to express what we're
actually trying to get at it, flexible array members.

PR kern/57304

Reported-by: syzbot+7fb1047f5dfa33b26331@syzkaller.appspotmail.com


# 1.71 27-Mar-2023 nakayama

Use PRIuBUSSIZE to print bus_size_t variables.


# 1.70 27-Mar-2023 riastradh

virtio(4): Avoid name collision with global intrhand on sparc64.

Pacifies -Werror=shadow.

No functional change intended.


# 1.69 25-Mar-2023 yamaguchi

Setup virtqueues after registering them to virtio_softc


# 1.68 24-Mar-2023 yamaguchi

Added check of pointer for allocated memory before release of resource


# 1.67 23-Mar-2023 yamaguchi

Added functions to set interrupt handler and index into virtqueue


# 1.66 23-Mar-2023 yamaguchi

Set virtqueues in virtio_child_attach_finish

The number of virtqueue maybe change in a part of VirtIO devices
(e.g. vioif(4)). And it is fixed after negotiation of features.
So the configuration is moved into the function.


# 1.65 03-Jan-2023 jakllsch

Subtly adjust criteria for notification of Virtio devices in
VIRTIO_F_RING_EVENT_IDX mode.

This fixes stalls in the vioif(4) transmit path that would happen sooner
or later, depending on interface transmit utilization, and were
particularly noticable with a NetBSD guest transmitting to its x86 KVM
host at multi-gigabit speeds.


# 1.64 30-Dec-2022 jakllsch

Fix dmamap_syncs more; the number of ring elements is vq->vq_num, not
sc->sc_nvqs.


Revision tags: netbsd-10-base
# 1.63 31-Oct-2022 simonb

branches: 1.63.2;
Use PRIx64 in a debug print macro to print a uint64_t.


# 1.62 18-Oct-2022 skrll

KNF


# 1.61 17-Oct-2022 skrll

Fix previous by using roundup (and not howmany).


# 1.60 15-Oct-2022 riastradh

virtio(4): Use howmany from sys/param.h instead of open-coding it.

howmany will divide by VIRTIO_PAGE_SIZE instead of doing &
~(VIRTIO_PAGE_SIZE - 1), but it's a constant 4096 so this should make
no difference in the compiled output except possibly at -O0.

No functional change intended.


# 1.59 15-Oct-2022 riastradh

virtio(4): Sprinkle KNF.

No functional change intended.


Revision tags: bouyer-sunxi-drm-base
# 1.58 14-Aug-2022 riastradh

virtio(4): Print numeric device type, even if unrecognized.


# 1.57 12-Aug-2022 riastradh

virtio(4): Membar and bus_dmamap_sync audit.

- Don't use membar_* for DMA.

- Sync only the header and payload of the rings separately as needed.
If we bounce, this avoids large memcpy when we only care about the
header.

- Sync uring with PREREAD before triggering anything that will return
data in it.

=> Move uring PREREAD in virtio_enqueue_commit to _before_ updating
vq->vq_avail->idx, which is the pointat which the DMA read is
triggered in the `device' (host).

=> Omit needless membar_consumer in virtio_enqueue_commit -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync uring PREREAD here.

=> XXX Does the device/host ever return unsolicited entries in the
queue, or only solicited ones? If only solicited ones, the
PREREAD in virtio_init_vq is redundant.

- Sync uring with POSTREAD before we read from it. This way the DMA
read into our buffer has finished before we read from the buffer.

=> Add missing uring POSTREAD in virtio_vq_is_enqueued, between read of
vq->vq_used_idx and return to caller, so that the caller can
safely use virtio_dequeue.

=> Add missing uring POSTREADs in virtio_start_vq_intr:
. between entry from caller and the read of vq->vq_used_idx
. between the read of vq->vq_used_idx and return to caller,
so that the caller can safely use virtio_dequeue, just like
virtio_vq_is_enqueued

=> Move uring POSTREADs in virtio_enqueue_commit to _before_ reading
vq->vq_used->flags or *vq->vq_avail_event, not after.

- After we write to aring, sync it with PREWRITE. This way we finish
writing to our buffer before the DMA write from it.

=> Omit needless PREWRITE in virtio_init_vq -- we do the appropriate
PREWRITE in virtio_enqueue_commit now.

=> Convert membar_producer to bus_dmamap_sync PREWRITE in
virtio_enqueue_commit.

=> Omit incorrect aring POSTWRITE in virtio_enqueue_commit -- no need
because the DMA write may not have completed yet at this point,
and we already do a POSTWRITE in virtio_vq_is_enqueued.

=> Omit needless membar_producer in virtio_postpone_intr -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync PREWRITE here.

- After xfers to aring have completed, sync it with POSTWRITE.

=> Add missing aring POSTWRITE in virtio_free_vq, in case there are
paths from virtio_enqueue_commit to here that don't go through
virtio_is_enqueued. (If there are no such paths, then maybe we
should KASSERT(vq->vq_queued == 0) in virtio_free_vq.)


# 1.56 09-Aug-2022 riastradh

virtio(4): Move comment for virtio_vq_intr.

No functional change intended.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.78 21-Apr-2023 yamaguchi

virtio(4): change members of struct vring_desc_extra before free a slot

This prevents the following race condition.
1. Thread-A: calls virtio_dequeue_commit() and
puts a slot into free descriptor chain in vq_free_slot()
2. Thread-B: calls virtio_enqueue_prep() and get the slot stored by Thread-A
3. Thread-B: calls virtio_enqueue_reserve() and
changes desc_base and desc_free_idx for the slot
4. Thread-A: changes the same members updated by Thread-B

reported by hannken, thanks.


# 1.77 19-Apr-2023 yamaguchi

virtio(4): change variable name, nfc


# 1.76 19-Apr-2023 yamaguchi

Fix not to allocate unnecessary descriptor

fixes PR/57358


# 1.75 19-Apr-2023 yamaguchi

Use enumeration for state of a child driver instead of flags
and check its detaching by using sc->sc_child in virtio_softc

pointed out by riastradh, thanks.
fixes PR/57357


# 1.74 31-Mar-2023 yamaguchi

Added flags to store status of attaching a virtio device

This prevents a panic on reboot after a virtio device had called
virtio_child_attach_failed().


# 1.73 31-Mar-2023 yamaguchi

Use descriptor chain for free slots instead of vq_entry list

Descriptors can be chained by themself. And descriptors added to
avail ring or used ring are already chained. But it was not used
for unused descriptors and another linked list structure named
vq_entry was used.
The chain is also used for unused descriptors to make virtio(4)
simpler.


# 1.72 29-Mar-2023 riastradh

virtio(4): Fix sizing of virtqueue allocation.

vq->vq_avail[0].ring is a zero-length array, and thus sizeof is zero;
likewise vq->vq_used[0].ring.

Use vq->vq_avail[0].ring[0] and vq->vq_used[0].ring[0] to fix this
and restore the previous allocation sizing logic.

XXX We shouldn't use zero-length arrays here -- they are asking for
trouble like this, and C99 has a standard way to express what we're
actually trying to get at it, flexible array members.

PR kern/57304

Reported-by: syzbot+7fb1047f5dfa33b26331@syzkaller.appspotmail.com


# 1.71 27-Mar-2023 nakayama

Use PRIuBUSSIZE to print bus_size_t variables.


# 1.70 27-Mar-2023 riastradh

virtio(4): Avoid name collision with global intrhand on sparc64.

Pacifies -Werror=shadow.

No functional change intended.


# 1.69 25-Mar-2023 yamaguchi

Setup virtqueues after registering them to virtio_softc


# 1.68 24-Mar-2023 yamaguchi

Added check of pointer for allocated memory before release of resource


# 1.67 23-Mar-2023 yamaguchi

Added functions to set interrupt handler and index into virtqueue


# 1.66 23-Mar-2023 yamaguchi

Set virtqueues in virtio_child_attach_finish

The number of virtqueue maybe change in a part of VirtIO devices
(e.g. vioif(4)). And it is fixed after negotiation of features.
So the configuration is moved into the function.


# 1.65 03-Jan-2023 jakllsch

Subtly adjust criteria for notification of Virtio devices in
VIRTIO_F_RING_EVENT_IDX mode.

This fixes stalls in the vioif(4) transmit path that would happen sooner
or later, depending on interface transmit utilization, and were
particularly noticable with a NetBSD guest transmitting to its x86 KVM
host at multi-gigabit speeds.


# 1.64 30-Dec-2022 jakllsch

Fix dmamap_syncs more; the number of ring elements is vq->vq_num, not
sc->sc_nvqs.


Revision tags: netbsd-10-base
# 1.63 31-Oct-2022 simonb

branches: 1.63.2;
Use PRIx64 in a debug print macro to print a uint64_t.


# 1.62 18-Oct-2022 skrll

KNF


# 1.61 17-Oct-2022 skrll

Fix previous by using roundup (and not howmany).


# 1.60 15-Oct-2022 riastradh

virtio(4): Use howmany from sys/param.h instead of open-coding it.

howmany will divide by VIRTIO_PAGE_SIZE instead of doing &
~(VIRTIO_PAGE_SIZE - 1), but it's a constant 4096 so this should make
no difference in the compiled output except possibly at -O0.

No functional change intended.


# 1.59 15-Oct-2022 riastradh

virtio(4): Sprinkle KNF.

No functional change intended.


Revision tags: bouyer-sunxi-drm-base
# 1.58 14-Aug-2022 riastradh

virtio(4): Print numeric device type, even if unrecognized.


# 1.57 12-Aug-2022 riastradh

virtio(4): Membar and bus_dmamap_sync audit.

- Don't use membar_* for DMA.

- Sync only the header and payload of the rings separately as needed.
If we bounce, this avoids large memcpy when we only care about the
header.

- Sync uring with PREREAD before triggering anything that will return
data in it.

=> Move uring PREREAD in virtio_enqueue_commit to _before_ updating
vq->vq_avail->idx, which is the pointat which the DMA read is
triggered in the `device' (host).

=> Omit needless membar_consumer in virtio_enqueue_commit -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync uring PREREAD here.

=> XXX Does the device/host ever return unsolicited entries in the
queue, or only solicited ones? If only solicited ones, the
PREREAD in virtio_init_vq is redundant.

- Sync uring with POSTREAD before we read from it. This way the DMA
read into our buffer has finished before we read from the buffer.

=> Add missing uring POSTREAD in virtio_vq_is_enqueued, between read of
vq->vq_used_idx and return to caller, so that the caller can
safely use virtio_dequeue.

=> Add missing uring POSTREADs in virtio_start_vq_intr:
. between entry from caller and the read of vq->vq_used_idx
. between the read of vq->vq_used_idx and return to caller,
so that the caller can safely use virtio_dequeue, just like
virtio_vq_is_enqueued

=> Move uring POSTREADs in virtio_enqueue_commit to _before_ reading
vq->vq_used->flags or *vq->vq_avail_event, not after.

- After we write to aring, sync it with PREWRITE. This way we finish
writing to our buffer before the DMA write from it.

=> Omit needless PREWRITE in virtio_init_vq -- we do the appropriate
PREWRITE in virtio_enqueue_commit now.

=> Convert membar_producer to bus_dmamap_sync PREWRITE in
virtio_enqueue_commit.

=> Omit incorrect aring POSTWRITE in virtio_enqueue_commit -- no need
because the DMA write may not have completed yet at this point,
and we already do a POSTWRITE in virtio_vq_is_enqueued.

=> Omit needless membar_producer in virtio_postpone_intr -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync PREWRITE here.

- After xfers to aring have completed, sync it with POSTWRITE.

=> Add missing aring POSTWRITE in virtio_free_vq, in case there are
paths from virtio_enqueue_commit to here that don't go through
virtio_is_enqueued. (If there are no such paths, then maybe we
should KASSERT(vq->vq_queued == 0) in virtio_free_vq.)


# 1.56 09-Aug-2022 riastradh

virtio(4): Move comment for virtio_vq_intr.

No functional change intended.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.77 19-Apr-2023 yamaguchi

virtio(4): change variable name, nfc


# 1.76 19-Apr-2023 yamaguchi

Fix not to allocate unnecessary descriptor

fixes PR/57358


# 1.75 19-Apr-2023 yamaguchi

Use enumeration for state of a child driver instead of flags
and check its detaching by using sc->sc_child in virtio_softc

pointed out by riastradh, thanks.
fixes PR/57357


# 1.74 31-Mar-2023 yamaguchi

Added flags to store status of attaching a virtio device

This prevents a panic on reboot after a virtio device had called
virtio_child_attach_failed().


# 1.73 31-Mar-2023 yamaguchi

Use descriptor chain for free slots instead of vq_entry list

Descriptors can be chained by themself. And descriptors added to
avail ring or used ring are already chained. But it was not used
for unused descriptors and another linked list structure named
vq_entry was used.
The chain is also used for unused descriptors to make virtio(4)
simpler.


# 1.72 29-Mar-2023 riastradh

virtio(4): Fix sizing of virtqueue allocation.

vq->vq_avail[0].ring is a zero-length array, and thus sizeof is zero;
likewise vq->vq_used[0].ring.

Use vq->vq_avail[0].ring[0] and vq->vq_used[0].ring[0] to fix this
and restore the previous allocation sizing logic.

XXX We shouldn't use zero-length arrays here -- they are asking for
trouble like this, and C99 has a standard way to express what we're
actually trying to get at it, flexible array members.

PR kern/57304

Reported-by: syzbot+7fb1047f5dfa33b26331@syzkaller.appspotmail.com


# 1.71 27-Mar-2023 nakayama

Use PRIuBUSSIZE to print bus_size_t variables.


# 1.70 27-Mar-2023 riastradh

virtio(4): Avoid name collision with global intrhand on sparc64.

Pacifies -Werror=shadow.

No functional change intended.


# 1.69 25-Mar-2023 yamaguchi

Setup virtqueues after registering them to virtio_softc


# 1.68 24-Mar-2023 yamaguchi

Added check of pointer for allocated memory before release of resource


# 1.67 23-Mar-2023 yamaguchi

Added functions to set interrupt handler and index into virtqueue


# 1.66 23-Mar-2023 yamaguchi

Set virtqueues in virtio_child_attach_finish

The number of virtqueue maybe change in a part of VirtIO devices
(e.g. vioif(4)). And it is fixed after negotiation of features.
So the configuration is moved into the function.


# 1.65 03-Jan-2023 jakllsch

Subtly adjust criteria for notification of Virtio devices in
VIRTIO_F_RING_EVENT_IDX mode.

This fixes stalls in the vioif(4) transmit path that would happen sooner
or later, depending on interface transmit utilization, and were
particularly noticable with a NetBSD guest transmitting to its x86 KVM
host at multi-gigabit speeds.


# 1.64 30-Dec-2022 jakllsch

Fix dmamap_syncs more; the number of ring elements is vq->vq_num, not
sc->sc_nvqs.


Revision tags: netbsd-10-base
# 1.63 31-Oct-2022 simonb

branches: 1.63.2;
Use PRIx64 in a debug print macro to print a uint64_t.


# 1.62 18-Oct-2022 skrll

KNF


# 1.61 17-Oct-2022 skrll

Fix previous by using roundup (and not howmany).


# 1.60 15-Oct-2022 riastradh

virtio(4): Use howmany from sys/param.h instead of open-coding it.

howmany will divide by VIRTIO_PAGE_SIZE instead of doing &
~(VIRTIO_PAGE_SIZE - 1), but it's a constant 4096 so this should make
no difference in the compiled output except possibly at -O0.

No functional change intended.


# 1.59 15-Oct-2022 riastradh

virtio(4): Sprinkle KNF.

No functional change intended.


Revision tags: bouyer-sunxi-drm-base
# 1.58 14-Aug-2022 riastradh

virtio(4): Print numeric device type, even if unrecognized.


# 1.57 12-Aug-2022 riastradh

virtio(4): Membar and bus_dmamap_sync audit.

- Don't use membar_* for DMA.

- Sync only the header and payload of the rings separately as needed.
If we bounce, this avoids large memcpy when we only care about the
header.

- Sync uring with PREREAD before triggering anything that will return
data in it.

=> Move uring PREREAD in virtio_enqueue_commit to _before_ updating
vq->vq_avail->idx, which is the pointat which the DMA read is
triggered in the `device' (host).

=> Omit needless membar_consumer in virtio_enqueue_commit -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync uring PREREAD here.

=> XXX Does the device/host ever return unsolicited entries in the
queue, or only solicited ones? If only solicited ones, the
PREREAD in virtio_init_vq is redundant.

- Sync uring with POSTREAD before we read from it. This way the DMA
read into our buffer has finished before we read from the buffer.

=> Add missing uring POSTREAD in virtio_vq_is_enqueued, between read of
vq->vq_used_idx and return to caller, so that the caller can
safely use virtio_dequeue.

=> Add missing uring POSTREADs in virtio_start_vq_intr:
. between entry from caller and the read of vq->vq_used_idx
. between the read of vq->vq_used_idx and return to caller,
so that the caller can safely use virtio_dequeue, just like
virtio_vq_is_enqueued

=> Move uring POSTREADs in virtio_enqueue_commit to _before_ reading
vq->vq_used->flags or *vq->vq_avail_event, not after.

- After we write to aring, sync it with PREWRITE. This way we finish
writing to our buffer before the DMA write from it.

=> Omit needless PREWRITE in virtio_init_vq -- we do the appropriate
PREWRITE in virtio_enqueue_commit now.

=> Convert membar_producer to bus_dmamap_sync PREWRITE in
virtio_enqueue_commit.

=> Omit incorrect aring POSTWRITE in virtio_enqueue_commit -- no need
because the DMA write may not have completed yet at this point,
and we already do a POSTWRITE in virtio_vq_is_enqueued.

=> Omit needless membar_producer in virtio_postpone_intr -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync PREWRITE here.

- After xfers to aring have completed, sync it with POSTWRITE.

=> Add missing aring POSTWRITE in virtio_free_vq, in case there are
paths from virtio_enqueue_commit to here that don't go through
virtio_is_enqueued. (If there are no such paths, then maybe we
should KASSERT(vq->vq_queued == 0) in virtio_free_vq.)


# 1.56 09-Aug-2022 riastradh

virtio(4): Move comment for virtio_vq_intr.

No functional change intended.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.65 03-Jan-2023 jakllsch

Subtly adjust criteria for notification of Virtio devices in
VIRTIO_F_RING_EVENT_IDX mode.

This fixes stalls in the vioif(4) transmit path that would happen sooner
or later, depending on interface transmit utilization, and were
particularly noticable with a NetBSD guest transmitting to its x86 KVM
host at multi-gigabit speeds.


# 1.64 30-Dec-2022 jakllsch

Fix dmamap_syncs more; the number of ring elements is vq->vq_num, not
sc->sc_nvqs.


Revision tags: netbsd-10-base
# 1.63 31-Oct-2022 simonb

Use PRIx64 in a debug print macro to print a uint64_t.


# 1.62 18-Oct-2022 skrll

KNF


# 1.61 17-Oct-2022 skrll

Fix previous by using roundup (and not howmany).


# 1.60 15-Oct-2022 riastradh

virtio(4): Use howmany from sys/param.h instead of open-coding it.

howmany will divide by VIRTIO_PAGE_SIZE instead of doing &
~(VIRTIO_PAGE_SIZE - 1), but it's a constant 4096 so this should make
no difference in the compiled output except possibly at -O0.

No functional change intended.


# 1.59 15-Oct-2022 riastradh

virtio(4): Sprinkle KNF.

No functional change intended.


Revision tags: bouyer-sunxi-drm-base
# 1.58 14-Aug-2022 riastradh

virtio(4): Print numeric device type, even if unrecognized.


# 1.57 12-Aug-2022 riastradh

virtio(4): Membar and bus_dmamap_sync audit.

- Don't use membar_* for DMA.

- Sync only the header and payload of the rings separately as needed.
If we bounce, this avoids large memcpy when we only care about the
header.

- Sync uring with PREREAD before triggering anything that will return
data in it.

=> Move uring PREREAD in virtio_enqueue_commit to _before_ updating
vq->vq_avail->idx, which is the pointat which the DMA read is
triggered in the `device' (host).

=> Omit needless membar_consumer in virtio_enqueue_commit -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync uring PREREAD here.

=> XXX Does the device/host ever return unsolicited entries in the
queue, or only solicited ones? If only solicited ones, the
PREREAD in virtio_init_vq is redundant.

- Sync uring with POSTREAD before we read from it. This way the DMA
read into our buffer has finished before we read from the buffer.

=> Add missing uring POSTREAD in virtio_vq_is_enqueued, between read of
vq->vq_used_idx and return to caller, so that the caller can
safely use virtio_dequeue.

=> Add missing uring POSTREADs in virtio_start_vq_intr:
. between entry from caller and the read of vq->vq_used_idx
. between the read of vq->vq_used_idx and return to caller,
so that the caller can safely use virtio_dequeue, just like
virtio_vq_is_enqueued

=> Move uring POSTREADs in virtio_enqueue_commit to _before_ reading
vq->vq_used->flags or *vq->vq_avail_event, not after.

- After we write to aring, sync it with PREWRITE. This way we finish
writing to our buffer before the DMA write from it.

=> Omit needless PREWRITE in virtio_init_vq -- we do the appropriate
PREWRITE in virtio_enqueue_commit now.

=> Convert membar_producer to bus_dmamap_sync PREWRITE in
virtio_enqueue_commit.

=> Omit incorrect aring POSTWRITE in virtio_enqueue_commit -- no need
because the DMA write may not have completed yet at this point,
and we already do a POSTWRITE in virtio_vq_is_enqueued.

=> Omit needless membar_producer in virtio_postpone_intr -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync PREWRITE here.

- After xfers to aring have completed, sync it with POSTWRITE.

=> Add missing aring POSTWRITE in virtio_free_vq, in case there are
paths from virtio_enqueue_commit to here that don't go through
virtio_is_enqueued. (If there are no such paths, then maybe we
should KASSERT(vq->vq_queued == 0) in virtio_free_vq.)


# 1.56 09-Aug-2022 riastradh

virtio(4): Move comment for virtio_vq_intr.

No functional change intended.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.64 30-Dec-2022 jakllsch

Fix dmamap_syncs more; the number of ring elements is vq->vq_num, not
sc->sc_nvqs.


Revision tags: netbsd-10-base
# 1.63 31-Oct-2022 simonb

Use PRIx64 in a debug print macro to print a uint64_t.


# 1.62 18-Oct-2022 skrll

KNF


# 1.61 17-Oct-2022 skrll

Fix previous by using roundup (and not howmany).


# 1.60 15-Oct-2022 riastradh

virtio(4): Use howmany from sys/param.h instead of open-coding it.

howmany will divide by VIRTIO_PAGE_SIZE instead of doing &
~(VIRTIO_PAGE_SIZE - 1), but it's a constant 4096 so this should make
no difference in the compiled output except possibly at -O0.

No functional change intended.


# 1.59 15-Oct-2022 riastradh

virtio(4): Sprinkle KNF.

No functional change intended.


Revision tags: bouyer-sunxi-drm-base
# 1.58 14-Aug-2022 riastradh

virtio(4): Print numeric device type, even if unrecognized.


# 1.57 12-Aug-2022 riastradh

virtio(4): Membar and bus_dmamap_sync audit.

- Don't use membar_* for DMA.

- Sync only the header and payload of the rings separately as needed.
If we bounce, this avoids large memcpy when we only care about the
header.

- Sync uring with PREREAD before triggering anything that will return
data in it.

=> Move uring PREREAD in virtio_enqueue_commit to _before_ updating
vq->vq_avail->idx, which is the pointat which the DMA read is
triggered in the `device' (host).

=> Omit needless membar_consumer in virtio_enqueue_commit -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync uring PREREAD here.

=> XXX Does the device/host ever return unsolicited entries in the
queue, or only solicited ones? If only solicited ones, the
PREREAD in virtio_init_vq is redundant.

- Sync uring with POSTREAD before we read from it. This way the DMA
read into our buffer has finished before we read from the buffer.

=> Add missing uring POSTREAD in virtio_vq_is_enqueued, between read of
vq->vq_used_idx and return to caller, so that the caller can
safely use virtio_dequeue.

=> Add missing uring POSTREADs in virtio_start_vq_intr:
. between entry from caller and the read of vq->vq_used_idx
. between the read of vq->vq_used_idx and return to caller,
so that the caller can safely use virtio_dequeue, just like
virtio_vq_is_enqueued

=> Move uring POSTREADs in virtio_enqueue_commit to _before_ reading
vq->vq_used->flags or *vq->vq_avail_event, not after.

- After we write to aring, sync it with PREWRITE. This way we finish
writing to our buffer before the DMA write from it.

=> Omit needless PREWRITE in virtio_init_vq -- we do the appropriate
PREWRITE in virtio_enqueue_commit now.

=> Convert membar_producer to bus_dmamap_sync PREWRITE in
virtio_enqueue_commit.

=> Omit incorrect aring POSTWRITE in virtio_enqueue_commit -- no need
because the DMA write may not have completed yet at this point,
and we already do a POSTWRITE in virtio_vq_is_enqueued.

=> Omit needless membar_producer in virtio_postpone_intr -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync PREWRITE here.

- After xfers to aring have completed, sync it with POSTWRITE.

=> Add missing aring POSTWRITE in virtio_free_vq, in case there are
paths from virtio_enqueue_commit to here that don't go through
virtio_is_enqueued. (If there are no such paths, then maybe we
should KASSERT(vq->vq_queued == 0) in virtio_free_vq.)


# 1.56 09-Aug-2022 riastradh

virtio(4): Move comment for virtio_vq_intr.

No functional change intended.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.63 31-Oct-2022 simonb

Use PRIx64 in a debug print macro to print a uint64_t.


# 1.62 18-Oct-2022 skrll

KNF


# 1.61 17-Oct-2022 skrll

Fix previous by using roundup (and not howmany).


# 1.60 15-Oct-2022 riastradh

virtio(4): Use howmany from sys/param.h instead of open-coding it.

howmany will divide by VIRTIO_PAGE_SIZE instead of doing &
~(VIRTIO_PAGE_SIZE - 1), but it's a constant 4096 so this should make
no difference in the compiled output except possibly at -O0.

No functional change intended.


# 1.59 15-Oct-2022 riastradh

virtio(4): Sprinkle KNF.

No functional change intended.


Revision tags: bouyer-sunxi-drm-base
# 1.58 14-Aug-2022 riastradh

virtio(4): Print numeric device type, even if unrecognized.


# 1.57 12-Aug-2022 riastradh

virtio(4): Membar and bus_dmamap_sync audit.

- Don't use membar_* for DMA.

- Sync only the header and payload of the rings separately as needed.
If we bounce, this avoids large memcpy when we only care about the
header.

- Sync uring with PREREAD before triggering anything that will return
data in it.

=> Move uring PREREAD in virtio_enqueue_commit to _before_ updating
vq->vq_avail->idx, which is the pointat which the DMA read is
triggered in the `device' (host).

=> Omit needless membar_consumer in virtio_enqueue_commit -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync uring PREREAD here.

=> XXX Does the device/host ever return unsolicited entries in the
queue, or only solicited ones? If only solicited ones, the
PREREAD in virtio_init_vq is redundant.

- Sync uring with POSTREAD before we read from it. This way the DMA
read into our buffer has finished before we read from the buffer.

=> Add missing uring POSTREAD in virtio_vq_is_enqueued, between read of
vq->vq_used_idx and return to caller, so that the caller can
safely use virtio_dequeue.

=> Add missing uring POSTREADs in virtio_start_vq_intr:
. between entry from caller and the read of vq->vq_used_idx
. between the read of vq->vq_used_idx and return to caller,
so that the caller can safely use virtio_dequeue, just like
virtio_vq_is_enqueued

=> Move uring POSTREADs in virtio_enqueue_commit to _before_ reading
vq->vq_used->flags or *vq->vq_avail_event, not after.

- After we write to aring, sync it with PREWRITE. This way we finish
writing to our buffer before the DMA write from it.

=> Omit needless PREWRITE in virtio_init_vq -- we do the appropriate
PREWRITE in virtio_enqueue_commit now.

=> Convert membar_producer to bus_dmamap_sync PREWRITE in
virtio_enqueue_commit.

=> Omit incorrect aring POSTWRITE in virtio_enqueue_commit -- no need
because the DMA write may not have completed yet at this point,
and we already do a POSTWRITE in virtio_vq_is_enqueued.

=> Omit needless membar_producer in virtio_postpone_intr -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync PREWRITE here.

- After xfers to aring have completed, sync it with POSTWRITE.

=> Add missing aring POSTWRITE in virtio_free_vq, in case there are
paths from virtio_enqueue_commit to here that don't go through
virtio_is_enqueued. (If there are no such paths, then maybe we
should KASSERT(vq->vq_queued == 0) in virtio_free_vq.)


# 1.56 09-Aug-2022 riastradh

virtio(4): Move comment for virtio_vq_intr.

No functional change intended.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.62 18-Oct-2022 skrll

KNF


# 1.61 17-Oct-2022 skrll

Fix previous by using roundup (and not howmany).


# 1.60 15-Oct-2022 riastradh

virtio(4): Use howmany from sys/param.h instead of open-coding it.

howmany will divide by VIRTIO_PAGE_SIZE instead of doing &
~(VIRTIO_PAGE_SIZE - 1), but it's a constant 4096 so this should make
no difference in the compiled output except possibly at -O0.

No functional change intended.


# 1.59 15-Oct-2022 riastradh

virtio(4): Sprinkle KNF.

No functional change intended.


Revision tags: bouyer-sunxi-drm-base
# 1.58 14-Aug-2022 riastradh

virtio(4): Print numeric device type, even if unrecognized.


# 1.57 12-Aug-2022 riastradh

virtio(4): Membar and bus_dmamap_sync audit.

- Don't use membar_* for DMA.

- Sync only the header and payload of the rings separately as needed.
If we bounce, this avoids large memcpy when we only care about the
header.

- Sync uring with PREREAD before triggering anything that will return
data in it.

=> Move uring PREREAD in virtio_enqueue_commit to _before_ updating
vq->vq_avail->idx, which is the pointat which the DMA read is
triggered in the `device' (host).

=> Omit needless membar_consumer in virtio_enqueue_commit -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync uring PREREAD here.

=> XXX Does the device/host ever return unsolicited entries in the
queue, or only solicited ones? If only solicited ones, the
PREREAD in virtio_init_vq is redundant.

- Sync uring with POSTREAD before we read from it. This way the DMA
read into our buffer has finished before we read from the buffer.

=> Add missing uring POSTREAD in virtio_vq_is_enqueued, between read of
vq->vq_used_idx and return to caller, so that the caller can
safely use virtio_dequeue.

=> Add missing uring POSTREADs in virtio_start_vq_intr:
. between entry from caller and the read of vq->vq_used_idx
. between the read of vq->vq_used_idx and return to caller,
so that the caller can safely use virtio_dequeue, just like
virtio_vq_is_enqueued

=> Move uring POSTREADs in virtio_enqueue_commit to _before_ reading
vq->vq_used->flags or *vq->vq_avail_event, not after.

- After we write to aring, sync it with PREWRITE. This way we finish
writing to our buffer before the DMA write from it.

=> Omit needless PREWRITE in virtio_init_vq -- we do the appropriate
PREWRITE in virtio_enqueue_commit now.

=> Convert membar_producer to bus_dmamap_sync PREWRITE in
virtio_enqueue_commit.

=> Omit incorrect aring POSTWRITE in virtio_enqueue_commit -- no need
because the DMA write may not have completed yet at this point,
and we already do a POSTWRITE in virtio_vq_is_enqueued.

=> Omit needless membar_producer in virtio_postpone_intr -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync PREWRITE here.

- After xfers to aring have completed, sync it with POSTWRITE.

=> Add missing aring POSTWRITE in virtio_free_vq, in case there are
paths from virtio_enqueue_commit to here that don't go through
virtio_is_enqueued. (If there are no such paths, then maybe we
should KASSERT(vq->vq_queued == 0) in virtio_free_vq.)


# 1.56 09-Aug-2022 riastradh

virtio(4): Move comment for virtio_vq_intr.

No functional change intended.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.61 17-Oct-2022 skrll

Fix previous by using roundup (and not howmany).


# 1.60 15-Oct-2022 riastradh

virtio(4): Use howmany from sys/param.h instead of open-coding it.

howmany will divide by VIRTIO_PAGE_SIZE instead of doing &
~(VIRTIO_PAGE_SIZE - 1), but it's a constant 4096 so this should make
no difference in the compiled output except possibly at -O0.

No functional change intended.


# 1.59 15-Oct-2022 riastradh

virtio(4): Sprinkle KNF.

No functional change intended.


Revision tags: bouyer-sunxi-drm-base
# 1.58 14-Aug-2022 riastradh

virtio(4): Print numeric device type, even if unrecognized.


# 1.57 12-Aug-2022 riastradh

virtio(4): Membar and bus_dmamap_sync audit.

- Don't use membar_* for DMA.

- Sync only the header and payload of the rings separately as needed.
If we bounce, this avoids large memcpy when we only care about the
header.

- Sync uring with PREREAD before triggering anything that will return
data in it.

=> Move uring PREREAD in virtio_enqueue_commit to _before_ updating
vq->vq_avail->idx, which is the pointat which the DMA read is
triggered in the `device' (host).

=> Omit needless membar_consumer in virtio_enqueue_commit -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync uring PREREAD here.

=> XXX Does the device/host ever return unsolicited entries in the
queue, or only solicited ones? If only solicited ones, the
PREREAD in virtio_init_vq is redundant.

- Sync uring with POSTREAD before we read from it. This way the DMA
read into our buffer has finished before we read from the buffer.

=> Add missing uring POSTREAD in virtio_vq_is_enqueued, between read of
vq->vq_used_idx and return to caller, so that the caller can
safely use virtio_dequeue.

=> Add missing uring POSTREADs in virtio_start_vq_intr:
. between entry from caller and the read of vq->vq_used_idx
. between the read of vq->vq_used_idx and return to caller,
so that the caller can safely use virtio_dequeue, just like
virtio_vq_is_enqueued

=> Move uring POSTREADs in virtio_enqueue_commit to _before_ reading
vq->vq_used->flags or *vq->vq_avail_event, not after.

- After we write to aring, sync it with PREWRITE. This way we finish
writing to our buffer before the DMA write from it.

=> Omit needless PREWRITE in virtio_init_vq -- we do the appropriate
PREWRITE in virtio_enqueue_commit now.

=> Convert membar_producer to bus_dmamap_sync PREWRITE in
virtio_enqueue_commit.

=> Omit incorrect aring POSTWRITE in virtio_enqueue_commit -- no need
because the DMA write may not have completed yet at this point,
and we already do a POSTWRITE in virtio_vq_is_enqueued.

=> Omit needless membar_producer in virtio_postpone_intr -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync PREWRITE here.

- After xfers to aring have completed, sync it with POSTWRITE.

=> Add missing aring POSTWRITE in virtio_free_vq, in case there are
paths from virtio_enqueue_commit to here that don't go through
virtio_is_enqueued. (If there are no such paths, then maybe we
should KASSERT(vq->vq_queued == 0) in virtio_free_vq.)


# 1.56 09-Aug-2022 riastradh

virtio(4): Move comment for virtio_vq_intr.

No functional change intended.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.58 14-Aug-2022 riastradh

virtio(4): Print numeric device type, even if unrecognized.


# 1.57 12-Aug-2022 riastradh

virtio(4): Membar and bus_dmamap_sync audit.

- Don't use membar_* for DMA.

- Sync only the header and payload of the rings separately as needed.
If we bounce, this avoids large memcpy when we only care about the
header.

- Sync uring with PREREAD before triggering anything that will return
data in it.

=> Move uring PREREAD in virtio_enqueue_commit to _before_ updating
vq->vq_avail->idx, which is the pointat which the DMA read is
triggered in the `device' (host).

=> Omit needless membar_consumer in virtio_enqueue_commit -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync uring PREREAD here.

=> XXX Does the device/host ever return unsolicited entries in the
queue, or only solicited ones? If only solicited ones, the
PREREAD in virtio_init_vq is redundant.

- Sync uring with POSTREAD before we read from it. This way the DMA
read into our buffer has finished before we read from the buffer.

=> Add missing uring POSTREAD in virtio_vq_is_enqueued, between read of
vq->vq_used_idx and return to caller, so that the caller can
safely use virtio_dequeue.

=> Add missing uring POSTREADs in virtio_start_vq_intr:
. between entry from caller and the read of vq->vq_used_idx
. between the read of vq->vq_used_idx and return to caller,
so that the caller can safely use virtio_dequeue, just like
virtio_vq_is_enqueued

=> Move uring POSTREADs in virtio_enqueue_commit to _before_ reading
vq->vq_used->flags or *vq->vq_avail_event, not after.

- After we write to aring, sync it with PREWRITE. This way we finish
writing to our buffer before the DMA write from it.

=> Omit needless PREWRITE in virtio_init_vq -- we do the appropriate
PREWRITE in virtio_enqueue_commit now.

=> Convert membar_producer to bus_dmamap_sync PREWRITE in
virtio_enqueue_commit.

=> Omit incorrect aring POSTWRITE in virtio_enqueue_commit -- no need
because the DMA write may not have completed yet at this point,
and we already do a POSTWRITE in virtio_vq_is_enqueued.

=> Omit needless membar_producer in virtio_postpone_intr -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync PREWRITE here.

- After xfers to aring have completed, sync it with POSTWRITE.

=> Add missing aring POSTWRITE in virtio_free_vq, in case there are
paths from virtio_enqueue_commit to here that don't go through
virtio_is_enqueued. (If there are no such paths, then maybe we
should KASSERT(vq->vq_queued == 0) in virtio_free_vq.)


# 1.56 09-Aug-2022 riastradh

virtio(4): Move comment for virtio_vq_intr.

No functional change intended.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.57 12-Aug-2022 riastradh

virtio(4): Membar and bus_dmamap_sync audit.

- Don't use membar_* for DMA.

- Sync only the header and payload of the rings separately as needed.
If we bounce, this avoids large memcpy when we only care about the
header.

- Sync uring with PREREAD before triggering anything that will return
data in it.

=> Move uring PREREAD in virtio_enqueue_commit to _before_ updating
vq->vq_avail->idx, which is the pointat which the DMA read is
triggered in the `device' (host).

=> Omit needless membar_consumer in virtio_enqueue_commit -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync uring PREREAD here.

=> XXX Does the device/host ever return unsolicited entries in the
queue, or only solicited ones? If only solicited ones, the
PREREAD in virtio_init_vq is redundant.

- Sync uring with POSTREAD before we read from it. This way the DMA
read into our buffer has finished before we read from the buffer.

=> Add missing uring POSTREAD in virtio_vq_is_enqueued, between read of
vq->vq_used_idx and return to caller, so that the caller can
safely use virtio_dequeue.

=> Add missing uring POSTREADs in virtio_start_vq_intr:
. between entry from caller and the read of vq->vq_used_idx
. between the read of vq->vq_used_idx and return to caller,
so that the caller can safely use virtio_dequeue, just like
virtio_vq_is_enqueued

=> Move uring POSTREADs in virtio_enqueue_commit to _before_ reading
vq->vq_used->flags or *vq->vq_avail_event, not after.

- After we write to aring, sync it with PREWRITE. This way we finish
writing to our buffer before the DMA write from it.

=> Omit needless PREWRITE in virtio_init_vq -- we do the appropriate
PREWRITE in virtio_enqueue_commit now.

=> Convert membar_producer to bus_dmamap_sync PREWRITE in
virtio_enqueue_commit.

=> Omit incorrect aring POSTWRITE in virtio_enqueue_commit -- no need
because the DMA write may not have completed yet at this point,
and we already do a POSTWRITE in virtio_vq_is_enqueued.

=> Omit needless membar_producer in virtio_postpone_intr -- may not
work with DMA memory, and even if it does, redundant with
bus_dmamap_sync PREWRITE here.

- After xfers to aring have completed, sync it with POSTWRITE.

=> Add missing aring POSTWRITE in virtio_free_vq, in case there are
paths from virtio_enqueue_commit to here that don't go through
virtio_is_enqueued. (If there are no such paths, then maybe we
should KASSERT(vq->vq_queued == 0) in virtio_free_vq.)


# 1.56 09-Aug-2022 riastradh

virtio(4): Move comment for virtio_vq_intr.

No functional change intended.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.56 09-Aug-2022 riastradh

virtio(4): Move comment for virtio_vq_intr.

No functional change intended.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.55 18-Jun-2022 andvar

fix typos in word "functions" in comments, mainly s/fuctions/functions/.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.54 24-Apr-2022 uwe

virtio: cosmetics - use (*pfn)(...) syntax.

Some people prefer to call function pointers without an explicit
dereference (that is purely cosmetic in this position), especially to
create faux c++ s->pfn(...) with function pointers in struct members.
Some prefer explicit dereference (that requires parens around it).

(pfn)(...) without dereference but with parens looks odd to both, so
make it conform to one of the established alternatives.

Same object code is generated.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.53 28-Oct-2021 yamaguchi

virtio: stop reinit for safety when a device resetting is failed


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.52 21-Oct-2021 yamaguchi

virtio: fix missing release of interrupt resources


# 1.51 21-Oct-2021 yamaguchi

virtio: reconfigure MSI-X vector on re-initialization

This may fix a problem that some interrupts, for example
link-state change of vioif(4) are not notified.


# 1.50 21-Oct-2021 yamaguchi

divide setup routine of virtio interrupts
into establishment and device configuration


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


# 1.42 17-Sep-2020 jakllsch

branches: 1.42.2;
Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.49 07-Feb-2021 skrll

In virtio_alloc_vq change BUS_DMA_NOWAIT to BUS_DMA_WAITOK. It's always
called from attach routines.


# 1.48 07-Feb-2021 skrll

Trailing whitespace


# 1.47 05-Feb-2021 reinoud

Better reading of 4.1.3.1, it seems that using 32 bit reads/writes is
mandatory for non-legacy devices.


# 1.46 05-Feb-2021 reinoud

Second round of cleaning up endian code. No more tailored code to maintain.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


Revision tags: thorpej-futex-base
# 1.42 17-Sep-2020 jakllsch

Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.45 28-Jan-2021 reinoud

Rewrite and streamline virtio device config read/write and explicitly cater
for the Aarch64-eb bus problem with Qemu. This removes lots of bus_space
`magic' and cleans up the code.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


Revision tags: thorpej-futex-base
# 1.42 17-Sep-2020 jakllsch

Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.44 20-Jan-2021 reinoud

Remove the virtio child driver finalisation check KASSERT that, while it
should never trigger, a possible bug in a child driver shouldn't have to panic
the kernel. Instead report the internal error.


# 1.43 20-Jan-2021 reinoud

Add VirtIO PCI v1.0 attachments and fix the drivers affected.

The vioif, ld, scsi, viornd and viomb devices were adjusted when needed and
tested both in legacy 0.9 and v1.0 attachments trough PCI on amd64, sparc64,
aarch64 and aarch64-eb. ACPI/FDT attachments also tested on
aarch64/aarch64-eb.

Known issues

* viomb on aarch64 works only with ACPI/FDT attachment but not with PCI
attachment. PCI and ACPI/FDT attachment works on aarch64-eb.

* virtio on sparc64 attaches but is it not functioning though not a
regression.


Revision tags: thorpej-futex-base
# 1.42 17-Sep-2020 jakllsch

Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.42 17-Sep-2020 jakllsch

Fix word-o of function name in comment


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.41 25-May-2020 yamaguchi

Set handlers implemented in child device of virtio(4) to virtqueue
instead of the commonized function


# 1.40 25-May-2020 yamaguchi

Register an interrupt handler for virtqueue to that for pci
to reduce function call


# 1.39 25-May-2020 yamaguchi

Remove VIRTIO_F_PCI_INTR_SOFTINT support for multiqueue

The functionality is no longer used by obsolating VIOIF_SOFTINT_INTR.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1 ad-namecache-base phil-wifi-20191119
# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.38 01-Oct-2019 chs

in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.


Revision tags: netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

branches: 1.35.2;
Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


Revision tags: isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.37 14-Jan-2019 yamaguchi

Add multiqueue support, virtio(4)


Revision tags: pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020
# 1.36 30-Sep-2018 jmcneill

Suppress "not configured" message when no device is present


Revision tags: pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.35 15-Jun-2018 jakllsch

Add cfprint_t virtiobusprint() and use it for virtio_mmio.


# 1.34 15-Jun-2018 jakllsch

Fix queue address setup bug introduced in 1.31.

This use-before-initialization problem resulted in non-zero queues never
being initialized with their virtqueue pointer, and queue zero's pointer
to be clobbered with the virtqueue pointer for the higest-indexed ring.


# 1.33 06-Jun-2018 jakllsch

remove now-irrelevant <dev/pci> includes


# 1.32 06-Jun-2018 jakllsch

fix up virtio module for current structure; add virtio_pci module


# 1.31 02-Jun-2018 jakllsch

Begin to detangle virtio from its PCI attachment


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.30 14-Feb-2018 uwe

branches: 1.30.2;
Cosmetic - consistently use #define<SPACE>


Revision tags: tls-maxphys-base-20171202 nick-nhusb-base-20170825
# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

branches: 1.28.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.29 02-Aug-2017 cherry

Reorg the virtio(4) config(9) code to be explicitly pci specific.

We'll later use this for a non-pci virtio(4) usecase.

ok martin


Revision tags: perseant-stdc-iso10646-base netbsd-8-base
# 1.28 01-Jun-2017 chs

remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


# 1.28 01-Jun-2017 chs

remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


Revision tags: prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base
# 1.27 28-Mar-2017 ozaki-r

Handle config change interrupts to inhibit sending packets while link down

PR kern/52103 by s-yamaguchi@IIJ


# 1.26 26-Mar-2017 jdolecek

fix pasto for nbo_bus_space_write_4() - value needs to be uint32_t


# 1.25 26-Mar-2017 martin

Duh, remove accidently left over debug printfs


# 1.24 26-Mar-2017 martin

Backout previous, no need for these accessor in MD code


# 1.23 26-Mar-2017 martin

Provide an accessor for the pci attach args of a virtio device (if
available - future non-pci attachments may return NULL).
Sparc64 MD code needs this to match the OF node of the virtio device
for boot device recognition.


# 1.22 25-Mar-2017 jdolecek

reorganize the attachment process for virtio child devices, so that
more common code is shared among the drivers, and it's possible for
the drivers to be correctly dynamically loaded; forbid direct access
to struct virtio_softc from the child driver code


# 1.21 25-Mar-2017 jdolecek

use ipl level specified by child when attaching interrupts, instead of always
using IPL_NET


# 1.20 25-Mar-2017 martin

PR kern/52107: for now (while we still use the legacy virtio spec) at least
hack around the endianess issues with that.


Revision tags: pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

branches: 1.19.2;
Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2; 1.6.6;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.


Revision tags: nick-nhusb-base-20161204
# 1.19 29-Nov-2016 uwe

Fix the "typical usage" example for enqueuing a request - if
bus_dmamap_load(9) fails, we shouldn't call bus_dmamap_unload(9).


Revision tags: pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.18 27-Sep-2016 pgoyette

Modularize the ld driver and all of its attachments. Ensure that all
parents are capable of rescan (or otherwise provide a means of attaching
children post-initialization).


Revision tags: localcount-20160914
# 1.17 14-Aug-2016 tron

Prevent a panic during system shutdown when vioif(4) is used


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.16 11-Jul-2016 knakahara

branches: 1.16.2;
pci_intr_type() is required pci_chipset_tag_t argument by other than x86.

pointed out by nonaka@n.o.


Revision tags: nick-nhusb-base-20160907
# 1.15 07-Jul-2016 msaitoh

KNF. Remove extra spaces. No functional change.


Revision tags: nick-nhusb-base-20160529 nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.14 10-Jan-2016 christos

PR/50636: Ryo ONODERA: Fix incorrect kmem_free()


Revision tags: nick-nhusb-base-20151226
# 1.13 30-Oct-2015 christos

more device names


# 1.12 27-Oct-2015 christos

use dma64 if available so we don't have do bounce around too much.


# 1.11 26-Oct-2015 ozaki-r

Support MSI-X in virtio

Currently only vioif(4) uses the feature.

knakahara@ helped to migrate to pci_intr_alloc(9). Thanks!


# 1.10 15-Oct-2015 ozaki-r

Name the interrupt handler for intrctl


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606
# 1.9 05-May-2015 ozaki-r

Remove a garbage blank line


Revision tags: nick-nhusb-base-20150406
# 1.8 19-Dec-2014 ozaki-r

Implement softint-based interrupt handling in if_vioif

Softint-based interrupt handling is considered as a future direction
of the (network) device driver architecture in NetBSD. pq3etsec of
ppc is already implemented based on the architecture (unlike pq3etsec,
this change doesn't include softint-based if_start). In this
architecture, a hardware interrupt handler just schedules a softint
and the softint performs actual interrupt processing. It reduces
processing in hardware interrupt context and allows Layer 2 network
stack (e.g., bridge, vlan and even bpf) run in softint context,
which makes it easy to implement fine-grain locking in the layer.

This is an experimental implementation of the architecture in if_viof.

virtio introduces a new flag VIRTIO_F_PCI_INTR_SOFTINT. If a driver
of virtio sets it to sc_flags of virtio_softc, virtio calls
softint_schedule in virtio_intr instead of directly calling the
interrupt handler of the driver.

When VIOIF_SOFTINT_INTR is on, vioif doesn't use the existing softint
(vioif_rx_softint) that is called from vioif_rx_vq_done. Because
vioif_rx_softint already runs in softint context and another softint
isn't needed. This change actually improves performance in some cases.

The feature is disabled by default and enabled when SOFTINT_INTR is
set somewhere (normally in a kernel configuration).


Revision tags: nick-nhusb-base
# 1.7 06-Oct-2014 mlelstv

branches: 1.7.2;
use correct macro to handle subsys ids. Functional there is no
change, as both macros select the same bits.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.6 22-Jul-2014 ozaki-r

branches: 1.6.2;
Introduce VIRTIO_F_PCI_INTR_MPSAFE for virtio

It is set by a child driver, e.g., if_vioif. If set, virtio sets
PCI_INTR_MPSAFE for pci_intr_establish.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 rmind-smpnet-nbase rmind-smpnet-base
# 1.5 29-Mar-2014 christos

branches: 1.5.2;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.


Revision tags: riastradh-drm2-base3
# 1.4 10-Aug-2013 tsutsui

Make sure to check if the driver has a valid intr handler in virtio_detach().

Fixes a panic during shutdown on KVM under ubuntu 13.04 with virtio,
as reported in PR kern/48105 by Richard Hansen.

Should be pulled up to netbsd-6 branches.


Revision tags: netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8 jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2
# 1.3 02-Nov-2011 njoly

branches: 1.3.6; 1.3.8; 1.3.12; 1.3.14; 1.3.16; 1.3.22;
Small typo in symbolic name.


Revision tags: yamt-pagecache-base
# 1.2 02-Nov-2011 jakllsch

branches: 1.2.2;
Use symbolic PCI_PRODUCTs.


# 1.1 30-Oct-2011 hannken

Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.